PAC-K007 · time-functions-usage

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

medium · 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.

Examples

Bad

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

Good

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

Engine behaviour

EngineBehaviourSource
chromiumweekdayRange, 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.lab, verified 2026-10-11 · ref
firefoxSame as Chromium.lab, verified 2026-10-11
pacparserNo 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.lab, verified 2026-10-04
winhttpdateRange 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.lab, verified 2026-10-11

Source: code = read in the engine's source, doc = vendor documentation, lab = observed in a lab run, expert = practitioner knowledge, not yet verified.

The PAC functions this rule is about

  • weekdayRange(): True on the given weekday or within the weekday range (SUN, MON, ... SAT). Local time unless "GMT" is passed.
  • dateRange(): True if the current date is within the given day, month and/or year range.
  • timeRange(): True if the current time is within the given hour/minute/second range.

Related rules

References

Last updated: