Repository navigation
feat: write date-times in a named zone (TZID + VTIMEZONE) - #27
Conversation
RFC 5545 3.6.5 requires a VTIMEZONE for every TZID; to write a named
zone the library has to produce one. It is built from Intl's offsets
since 1970: yearly rules as RRULE runs (the current one open, so an
unbounded series is covered), other changes by date, and read back
against Intl before use. ical.js reads times before the first
observance as offset 0 and ignores DTSTART in an observance with
RDATEs, so the form anchors the start and repeats DTSTART. A UTC
offset name ("+01:00"), which newer Intl accepts, is no TZID.
Refs #4
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The library could keep a TZID but not introduce one: a new value with Z or an offset was written as UTC, a zoneless one as floating, so a new recurring meeting drifted an hour in local time at each DST change. With zone, date-times are written as wall clock in that IANA zone with its TZID, and a VTIMEZONE is added when the VCALENDAR has none. Values that follow DTSTART are refused in another zone than DTSTART's unless DTSTART is in the call; moving a series into the zone is the existing series move, on the new zone's wall clock. floatingTime and absoluteTime "as-given" contradict zone and are refused with it. Refs #4 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Each generated VTIMEZONE is read with the library's reader and with ical.js and compared with Intl, for 16 zones chosen for southern DST, half- and quarter-hour offsets, rule changes and irregular rules; the option is checked end to end, including series expanded by ical.js across both 2026 DST changes. VTIMEZONE_DEEP and VTIMEZONE_ALL_ZONES enable the dense and the every-zone sweep. The smoke test checks both builds on the consumer's ical.js. Refs #4 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The README still listed named zones as unsupported and pointed to other libraries for time zones. It now describes the option, its precedence over floatingTime and absoluteTime, what moving a series into a zone means, the VTIMEZONE form and its limits, and the codes the option can raise. Refs #4 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The every-zone sweep found DST periods of one week that a weekly sample skips: Boa Vista, Recife and Noronha in October 2000, Gaza and Hebron in October 2040. Their generated VTIMEZONE missed those changes. Sampling daily finds them; the scan is cached per zone, so it costs about 200 ms once per zone and process. Refs #4 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Recife's one week of DST in 2000 and Gaza's in 2040 are now in the default zones, and every comparison starts where the VTIMEZONE does, so a zone that left local mean time after 1970 (Monrovia) is checked from then on instead of failing before it. Refs #4 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The zone option and the generated VTIMEZONE are new API; in 0.x that
is a minor bump. A TZID spelled as a UTC offset ("+01:00") is no
longer resolved through Intl.
Refs #4
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Review of #27 found four problems in the generated VTIMEZONE: - the scan cache kept every sample, keyed by value years: 36 MB for Cairo, over 900 MB for all zones. It now keeps one change list per zone, grown only by the years not yet scanned (1 MB for all); - Outlook takes the observances with the latest DTSTART as the rule (MS-OXCICAL 2.1.3.1.1.19.2), and those were abolished rules (Sao Paulo, Moscow, Tehran, ...). The final state now always comes last, as an open rule pair or the last change on its own; - Egypt's rule ending on the Friday after the last Thursday of October, sometimes 1 November, is now an open BYYEARDAY rule; - coverage starts the year before the earliest value instead of 1970, with TZNAME. An own VTIMEZONE is regenerated when a value moves before it; another one is refused there. Refs #4 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Writing DTSTART in a zone left DTEND in the old zone: a Berlin 10:00-11:00 meeting moved to 10:00 New York ended at 09:00Z, before its 14:00Z start, and the ZONE_MISMATCH remedy told callers to do exactly that. An end the call does not write now moves along, keeping its duration; an end before the start is refused with the new code END_BEFORE_START. zone "UTC" (and its aliases) is written with Z and no VTIMEZONE, and a lower-case alias is written as the zone it links to instead of in lower case. Refs #4 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
dav-mcp needs what updateFields uses internally: generateVtimezone for objects it builds itself, zone conversion that is right near DST changes (ical.js#847) with RFC 5545 3.3.5 gap and fold reading, and a recurrence expansion that cannot loop. expandOccurrences charges every candidate ical.js tests to a budget a caller can share across calls, through the same hook as the series checks, and reports an exhausted budget instead of running on. Refs #4 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Final state last for zones that abolished or changed DST, Cairo's rule, TZNAME, cache size, regeneration and refusal of an existing VTIMEZONE, ends moved with DTSTART, UTC zone, alias spelling, and each export, including the three rules that never end (DAILY on 30 February, SECONDLY and MINUTELY since 1950/1960). The smoke test checks the helpers in both builds. Refs #4 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The VTIMEZONE form (final state last, coverage, TZNAME, Ramadan zones), how an existing VTIMEZONE is treated, ends that move with DTSTART, zone UTC and alias spelling, ical.js' different reading of gap and fold times, a line for LLM tool callers, the new error code, and a section on the three helpers. Refs #4 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Node 18's ICU names Asia/Kathmandu NPT, later ones have no abbreviation for it; the fallback to the offset is checked on a zone no ICU names. Refs #4 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
An UNTIL in 9999 made the scan run to 10001 and the rule runs grow quadratically: 81 s for a weekly Berlin series. A value's last year no longer extends the scan, since the zone's settled rule or fixed offset covers every later year, and runs keep the candidate rules and narrow them per year. Now 70 ms. For Outlook, which reads the latest STANDARD and DAYLIGHT each on its own, a zone without DST now ends in both kinds at the same DTSTART. Refs #4 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
expandOccurrences gave an override without DTEND the master's end at the original slot, before its own start, and ignored its DURATION. A moved end measured in elapsed time was added on the wall clock, an hour off across a DST change. resolveZone and generateVtimezone kept a lower-case name instead of spelling it as updateFields does. Refs #4 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Refs #4 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Guards the 9999 UNTIL and a value in year 1 under 200 ms, checks the latest STANDARD and DAYLIGHT separately for Outlook from four start years, override ends, an elapsed end across a DST change, and the spelling of zone names in the helpers. Refs #4 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Refs #4 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Review summary: two reviewers (A correctness vs own RFC evaluator + Intl for all zones; B interop/consumer incl. live Baïkal), then two re-verify rounds. Fixed along the way: unbounded scan cache (903 MB → ~2 MB for all zones), Outlook/Exchange per-kind latest-observance rule (final state as latest STANDARD and DAYLIGHT), coverage from earliest year with regeneration of library-generated VTIMEZONEs and refusal for foreign ones, DTEND/DUE follow a zone change, far-future UNTIL (81 s → 72 ms), override ends in expandOccurrences, UTC aliases → Z. Final sweep: 0 mismatches over 1,688 VTIMEZONE texts with two readers; default path byte-identical to 0.6.0 over 60,000 calls. New exports for consumers: generateVtimezone, resolveZone/resolvePropertyZone, expandOccurrences + createRecurrenceBudget. Not verified: rendering in real Outlook. CI green on Node 18–26. |
Problem
The library could keep a
TZIDthat was already there, but couldn't add one. A new value given withZor an offset was written as UTC, and one without a zone as floating. A recurring meeting created that way (for example by dav-mcp'screate_event) was a UTC series, so its local time moved by an hour at every DST change. RFC 5545 3.6.5 also requires aVTIMEZONEfor everyTZID, and the library had no way to produce one.Change
zone: '<IANA name>'option. Every date-time the call writes is a wall-clock time in that zone and getsTZID=<zone>:Zor offset value becomes its wall-clock time in the zone. An instant in the second pass of the repeated hour has no wall-clock time there and throwsDST_AMBIGUOUS.UNTIL) are written in the zone when DTSTART is in the call. Without DTSTART in the call they are only written in the zone when DTSTART is already in it (or the component has no DTSTART). Otherwise they throwZONE_MISMATCHwith remedysame-call.zonedecides.floatingTime(either value) andabsoluteTime: 'as-given'contradict it, so giving them withzonethrowsINVALID_FLOATING_TIMEorINVALID_ABSOLUTE_TIME.keep-zoneagrees withzoneand may be given.CEST) or an offset (+01:00) throwsUNKNOWN_TZID.europe/berlinis writtenEurope/Berlin), and aliases are kept as given (Asia/Kolkata).VTIMEZONEdefines is accepted.zone, an end before its start throws the new codeEND_BEFORE_START.zone: 'UTC'(alsoEtc/UTC,GMT,Zulu) writesZ, with no TZID and no VTIMEZONE.Coverage starts on 1 January of the year before the earliest value. The first observance only states the offset at that start, because ical.js reads times before a VTIMEZONE's first observance as offset 0.
Yearly rules become RRULE pairs, ended by UNTIL where the rule stopped. Other changes are listed by RDATE, with DTSTART repeated among them because ical.js ignores DTSTART in an observance that has RDATEs.
Final state last, for Outlook. Outlook and Exchange read the zone's current rule from the latest STANDARD and the latest DAYLIGHT, each picked on its own (MS-OXCICAL 2.1.3.1.1.19.2, note <61>). Both describe the zone's final state:
An abolished DST rule, like Sao Paulo's, Moscow's or Tehran's, is never the latest of its kind.
TZNAME is the abbreviation from Intl (
CET,EST,IST); without one, the offset (-03).Rules crossing a month end are recognised. Egypt's DST ends on the Friday after the last Thursday of October, which can be 1 November; this becomes an open
BYYEARDAY=-67..-61;BYDAY=FRrule.Ramadan-based zones. Only Casablanca, El Aaiun, Gaza and Hebron are listed by date, up to 2087, where the tz database's own list ends. The median VTIMEZONE for a 2026 value is 9 lines.
Checks. The output is read back and compared with the zone's scanned changes before use, and the same input always gives the same text.
Scan length. A value's last year doesn't extend the scan: once the zone has settled, its final state covers every later year. Rule runs are built in linear time, so
UNTIL=99991231takes 70 ms (it was 81 s).Memory. The scan cache keeps one change list per zone, extended by scanning only missing years: about 1 MB for all 418 zones (it was over 900 MB).
Existing VTIMEZONE. One already in the object is reused. If a write in the zone puts a value before its first observance: a VTIMEZONE this library generated (byte-identical to what it would generate) is regenerated for the wider range; any other is refused with
UNSUPPORTED_VTIMEZONE(rewrite-object).Local mean time. A value on local mean time, whose offset is in seconds, throws
UNSUPPORTED_VTIMEZONE.generateVtimezone(tzid, { from, to? })returns the VTIMEZONE as text.resolveZone(tzid, source?)/resolvePropertyZone(property)convert UTC → wall time exactly (ical.js#847 does not) and wall → UTC per RFC 5545 §3.3.5. They read the object's VTIMEZONE, with IANA as fallback, from text or from a component of any ical.js copy.expandOccurrences(object, { budget, until, from?, limit? })(overrides end at their own DTEND, else their own DURATION, else the master's length from their own start), withcreateRecurrenceBudget()charges every ical.js candidate to a budget that can be shared across calls, using the same hook as the series checks. When the budget runs out it fails closed withcomplete: false, stoppedBy: 'budget'.ianaZoneno longer accepts a UTC offset (+01:00) as an IANA zone. Newer Intl versions accept it, but it is not a TZID.Tests
VTIMEZONE_ALL_ZONES=1covers all 418 zones from 1971 and from 2026: 0 mismatches, and every final state correct.VTIMEZONE_DEEP=1passes.END_BEFORE_START, the UTC zone, alias spelling, and regeneration vs. refusal of an existing VTIMEZONE (2020 and 1950 moves).mem.cjsand--expose-gc: all 418 zones retain 1 MB, Cairo 0.46 MB. 20 distinct Berlin UNTIL years take 103 ms and retain 0.64 MB.TZ=UTC,America/New_YorkandAsia/Kolkata(on the compute host).updateFields+zone, PUT (201), and read back with GET.expandwas not checked: this server answers every expand request with a 500, also for a plain UTC event.Breaking changes
None for callers that don't pass
zone: the default path is byte-identical to 0.6.0 over 60,000 calls (re-verified in review).Two TypeScript-only effects:
UpdateFieldsErrorCodegainsEND_BEFORE_START. An exhaustiveswitchover the codes (with anevercheck) stops compiling until it handles the new code.UPDATE_FIELDS_ERROR_CODEShas one more entry.One edge case: a
TZIDspelled as a UTC offset (+01:00) used to resolve through Intl on Node versions that accept it, and now throwsUNKNOWN_TZIDon every Node version.Closes #4
🤖 Generated with Claude Code