# Time functions that answer differently per engine (weekdayRange, dateRange, timeRange)

Source: https://findproxyforurl.net/rules/time-functions-usage/ · last updated 2026-10-15

Rule PAC-K007 (`time-functions-usage`), severity medium, category: Compatibility across engines.

On Windows, dateRange and timeRange are always false and weekdayRange fails on day names that are not in upper case. A range that wraps around (FRI to MON, DEC to JAN, 22:00 to 06:00) is matched by Chrome, Edge and Firefox but never by pactester, and timeRange(22, 6) is never true anywhere.

## Why it matters

The three time functions are evaluated with the client's local time unless `"GMT"` is
passed, so laptops in other timezones, wrong clocks and daylight saving transitions change
routing. Beyond that, the engines disagree on what the calls return.

Windows differs most. In the lab on Windows 11 (2026-10-11) `dateRange` and `timeRange`
returned false for every argument form tried, so a branch that depends on them never runs
for Windows programs, whatever the date or time. `weekdayRange` worked only with day names in
upper case: `weekdayRange("mon", "fri")` raised an error that ended the script, and
`weekdayRange("Sun")` was false on a Sunday. A weekday range across the weekend such as
`weekdayRange("FRI", "MON")` did wrap on Windows.

Ranges that wrap around differ between the other engines: `weekdayRange("FRI", "MON")`,
`dateRange("DEC", "JAN")` and `timeRange(22, 0, 6, 0)` wrap in Chrome, Edge and Firefox but
are never true in pactester (pacparser), and `timeRange(22, 6)` is never true in any engine
(lab, 2026-10-11).

The business need behind a time rule (a different proxy outside office hours, a maintenance
window) is better served on the proxy, which has a reliable clock and applies the policy to
every client in the same way.


## How to fix

Move time-dependent policy to the proxy. If a weekday rule must stay in the file, write day names in upper case ("MON", "FRI") and split a range that wraps around into two calls, e.g. weekdayRange("FRI", "SAT") || weekdayRange("SUN", "MON"). Do not rely on dateRange or timeRange, which never match on Windows.

## Bad

```js
function FindProxyForURL(url, host) {
  if (timeRange(22, 6) || weekdayRange("sat", "sun")) {
    return "PROXY night-proxy.corp.example:8080";
  }
  return "PROXY proxy.corp.example:8080";
}
```

## Good

```js
function FindProxyForURL(url, host) {
  if (weekdayRange("MON", "FRI")) {
    return "PROXY proxy.corp.example:8080";
  }
  return "PROXY weekend-proxy.corp.example:8080";
}
```

## Engine behaviour

- chromium: weekdayRange, dateRange and timeRange with hours and minutes wrap around (FRI to MON, DEC to JAN, 22:00 to 06:00); timeRange(22, 6) with two hours does not. (source: lab, verified 2026-10-11)
- firefox: Same as Chromium. (source: lab, verified 2026-10-11)
- pacparser: No wrap-around in weekdayRange or dateRange; such ranges are never true. Because the week starts on Sunday, weekdayRange("MON", "SUN") is a wrap-around range too and is always false. The source shows that timeRange works the same way. (source: lab, verified 2026-10-04)
- winhttp: dateRange and timeRange always return false, whatever the arguments. weekdayRange works with upper-case day names and wraps (FRI to MON); lower-case names raise an error or give false. (source: lab, verified 2026-10-11)
