Time.Disambiguation
type Time.Disambiguation = Time.Compatible | Time.Earlier | Time.LaterTime.Disambiguation says which instant to take for a wall-clock time that a daylight-saving change skipped or repeated in a zone. Such a time has no instant in a gap and two in an overlap; Time.possibleInstants lists them.
type Time.Compatible = {}Time.Compatible is the disambiguation that moves a wall-clock time in a gap forward by the length of the gap, as Time.Later does, and takes the earlier instant for one in an overlap. It is the default, and what the common date libraries do.
type Time.Earlier = {}Time.Earlier is the disambiguation that takes the earlier instant for a wall-clock time in an overlap, and reads one in a gap with the offset from after the change, which moves it back by the length of the gap.
type Time.Later = {}Time.Later is the disambiguation that takes the later instant for a wall-clock time in an overlap, and reads one in a gap with the offset from before the change, which moves it forward by the length of the gap.
Details
- The three members are records with no fields, so a value is written with braces:
Time.Compatible{},Time.Earlier{},Time.Later{}. - It matters only for a wall-clock time that is skipped or repeated. Every other time has one instant, and all three give it. Where a function takes one,
Time.Compatible{}is the default. Time.parseZoneduses it only for a string with a time and no offset, andTime.withonly when the value's own offset does not fit the new time. Time.add takes no disambiguation: it places aZonedDateTimemoved by days or more withCompatible.
Basic examples
On November 1, 2026, New York moves its clocks back from 02:00 to 01:00, so 01:30 happens twice. Time.Earlier takes the first, with the summer offset, and Time.Later the second:
let ny = Time.zone("America/New_York").unwrap()
let repeated = Time.parsePlainDateTime("2026-11-01T01:30").unwrap()
Time.toZoned(repeated, ny, disambiguation: Time.Earlier{}) // 2026-11-01T01:30:00-04:00[America/New_York]
Time.toZoned(repeated, ny, disambiguation: Time.Later{}) // 2026-11-01T01:30:00-05:00[America/New_York]
Time.toZoned(repeated, ny, disambiguation: Time.Compatible{}) // 2026-11-01T01:30:00-04:00[America/New_York]On March 8, 2026, the clocks jump from 02:00 to 03:00, so 02:30 never happens. Time.Earlier gives 01:30 at the winter offset, and Time.Later and Time.Compatible give 03:30 at the summer offset:
let ny = Time.zone("America/New_York").unwrap()
let skipped = Time.parsePlainDateTime("2026-03-08T02:30").unwrap()
Time.toZoned(skipped, ny, disambiguation: Time.Earlier{}) // 2026-03-08T01:30:00-05:00[America/New_York]
Time.toZoned(skipped, ny, disambiguation: Time.Later{}) // 2026-03-08T03:30:00-04:00[America/New_York]
Time.toZoned(skipped, ny, disambiguation: Time.Compatible{}) // 2026-03-08T03:30:00-04:00[America/New_York]Scope
A value of the union renders with its member's name, and compares equal to another of the same member:
let d: Time.Disambiguation = Time.Later{}
d // Time.Later{}
d is Time.Later // true
Time.Earlier{} == Time.Earlier{} // true
String.from(Time.Compatible{}) // "Time.Compatible{}"Test the member with is to branch on it:
func describe(d: Time.Disambiguation): string {
if d is Time.Earlier {
"the earlier instant"
} else if d is Time.Later {
"the later instant"
} else {
"later in a gap, earlier in an overlap"
}
}
println(describe(Time.Earlier{}))
println(describe(Time.Compatible{}))the earlier instant
later in a gap, earlier in an overlapKeep the members in an array and try each one:
let ny = Time.zone("America/New_York").unwrap()
let skipped = Time.parsePlainDateTime("2026-03-08T02:30").unwrap()
let all: Array[Time.Disambiguation] = [Time.Compatible{}, Time.Earlier{}, Time.Later{}]
for d in all {
println("${d}: ${skipped.toZoned(ny, disambiguation: d)}")
}Time.Compatible{}: 2026-03-08T03:30:00-04:00[America/New_York]
Time.Earlier{}: 2026-03-08T01:30:00-05:00[America/New_York]
Time.Later{}: 2026-03-08T03:30:00-04:00[America/New_York]Time.parseZoned resolves a string with a time and no offset by it:
Time.parseZoned("2026-11-01T01:30[America/New_York]", disambiguation: Time.Later{}) // Ok{ value: 2026-11-01T01:30:00-05:00[America/New_York] }Time.with uses it when the new wall-clock time is skipped:
let saturday = Time.parseZoned("2026-03-07T02:30[America/New_York]").unwrap()
saturday.with(day: 8, disambiguation: Time.Earlier{}) // 2026-03-08T01:30:00-05:00[America/New_York]
saturday.with(day: 8) // 2026-03-08T03:30:00-04:00[America/New_York]A zone that changes by half an hour, such as Lord Howe Island, has a half-hour gap:
let lordHowe = Time.zone("Australia/Lord_Howe").unwrap()
let skipped = Time.parsePlainDateTime("2026-10-04T02:15").unwrap()
skipped.toZoned(lordHowe, disambiguation: Time.Earlier{}) // 2026-10-04T01:45:00+10:30[Australia/Lord_Howe]
skipped.toZoned(lordHowe, disambiguation: Time.Later{}) // 2026-10-04T02:45:00+11:00[Australia/Lord_Howe]Applications
Read the choice from a configuration string:
func parseDisambiguation(s: string): Result[Time.Disambiguation, Error] {
if s == "earlier" { return Result.ok(Time.Earlier{}) }
if s == "later" { return Result.ok(Time.Later{}) }
if s == "compatible" { return Result.ok(Time.Compatible{}) }
Result.fail("unknown disambiguation ${s}")
}
println(parseDisambiguation("later"))
println(parseDisambiguation("first"))Ok{ value: Time.Later{} }
Err{ error: Error{ message: "unknown disambiguation first" } }A night shift that ends at 01:30 on the night the clocks go back lasts four or five hours, depending on which 01:30 the worker left at:
let ny = Time.zone("America/New_York").unwrap()
let start = Time.parsePlainDateTime("2026-10-31T21:30").unwrap().toZoned(ny)
let end = Time.parsePlainDateTime("2026-11-01T01:30").unwrap()
for d in [Time.Earlier{}, Time.Later{}] {
println(start.until(end.toZoned(ny, disambiguation: d)))
}PT4H
PT5HProperties and relations
In an overlap, Time.Earlier and Time.Later take the earlier and the later of the two instants Time.possibleInstants lists, and Time.Compatible takes the earlier:
let ny = Time.zone("America/New_York").unwrap()
let repeated = Time.parsePlainDateTime("2026-11-01T01:30").unwrap()
let both = repeated.possibleInstants(ny)
let early = repeated.toZoned(ny, disambiguation: Time.Earlier{})
let late = repeated.toZoned(ny, disambiguation: Time.Later{})
assert(both.length() == 2)
assert(both.some({ x == early.toInstant() }))
assert(both.some({ x == late.toInstant() }))
assert(Time.compare(early, late) == -1)
assert(repeated.toZoned(ny) == early)In a gap, Time.Compatible agrees with Time.Later:
let ny = Time.zone("America/New_York").unwrap()
let skipped = Time.parsePlainDateTime("2026-03-08T02:30").unwrap()
assert(skipped.possibleInstants(ny).length() == 0)
assert(skipped.toZoned(ny) == skipped.toZoned(ny, disambiguation: Time.Later{}))Possible issues
No disambiguation rejects a skipped or repeated time; each gives some instant. To refuse one, test the length of Time.possibleInstants instead:
func strict(t: Time.PlainDateTime, z: Time.Zone): Result[Time.ZonedDateTime, Error] {
if t.possibleInstants(z).length() != 1 {
return Result.fail("${t} is skipped or repeated in ${z}")
}
Result.ok(t.toZoned(z))
}
let ny = Time.zone("America/New_York").unwrap()
println(strict(Time.parsePlainDateTime("2026-11-01T01:30").unwrap(), ny))
println(strict(Time.parsePlainDateTime("2026-11-01T12:00").unwrap(), ny))Err{ error: Error{ message: "2026-11-01T01:30:00 is skipped or repeated in America/New_York" } }
Ok{ value: 2026-11-01T12:00:00-05:00[America/New_York] }A member is a type; write braces to make a value of it:
let ny = Time.zone("America/New_York").unwrap()
let repeated = Time.parsePlainDateTime("2026-11-01T01:30").unwrap()
let at = repeated.toZoned(ny, disambiguation: Time.Later)
// error: Time.Later is a type, not a value; a type appears only as a literal head, after is, or before a dotA string with an offset names its instant, so disambiguation has no say:
Time.parseZoned("2026-11-01T01:30-04:00[America/New_York]", disambiguation: Time.Later{}) // Ok{ value: 2026-11-01T01:30:00-04:00[America/New_York] }Time.with keeps the value's own offset when it fits the new time, so moving to the repeated hour from the summer side stays on the summer offset, whatever the disambiguation:
let october = Time.parseZoned("2026-10-31T01:30[America/New_York]").unwrap()
october.with(month: 11, day: 1, disambiguation: Time.Later{}) // 2026-11-01T01:30:00-04:00[America/New_York]Time.add has no disambiguation parameter; adding a day to a time that lands in a gap always moves forward, as Time.Compatible does:
let saturday = Time.parseZoned("2026-03-07T02:30[America/New_York]").unwrap()
let sunday = Time.add(saturday, Time.duration(days: 1), disambiguation: Time.Earlier{})
// error: Time.add has no parameter disambiguationSee also
Time.toZoned · Time.possibleInstants · Time.parseZoned · Time.with · Time.add · Time.nextTransition · Time.ZonedDateTime
