Time.Wall
type Time.Wall = Time.ZonedDateTime | Time.PlainDate | Time.PlainTime | Time.PlainDateTimeTime.Wall is the time types with fields, the ones Time.with serves.
Details
- A value typed
Time.Walldoes not pass toTime.withuntil anistest narrows it to one member. A function with a type parameter bounded byTime.Wallpasses its argument as it is. Time.Walladmits aPlainDateand aPlainTime, but each takes only its own fields:Time.withpanics on a time field of a date or a date field of a time.
Basic examples
A variable typed Time.Wall holds any of the four members:
let release: Time.Wall = Time.plainDate(2026, 4, 10)
release // 2026-04-10
release is Time.PlainDate // true
release is Time.PlainTime // falseA function whose type parameter is bounded by Time.Wall accepts every member and returns the type it was given. Each member must still have the fields it replaces, so this one takes the three members with a clock time:
func startOfMinute[T: Time.Wall](t: T): T {
Time.with(t, second: 0, millisecond: 0, microsecond: 0, nanosecond: 0)
}
let meeting = Time.parseZoned("2026-05-04T10:15:42.5[Europe/Paris]").unwrap()
println(startOfMinute(Time.plainTime(9, 30, 45)))
println(startOfMinute(meeting.toPlainDateTime()))
println(startOfMinute(meeting))09:30:00
2026-05-04T10:15:00
2026-05-04T10:15:00+02:00[Europe/Paris]On a PlainDate it panics, as Possible issues shows.
Scope
An array of Time.Wall mixes the members, and each renders as its own type does:
let meeting = Time.parseZoned("2026-05-04T10:00[Europe/Paris]").unwrap()
let marks: Array[Time.Wall] = [
Time.plainDate(2026, 5, 4),
Time.plainTime(10, 0),
meeting.toPlainDateTime(),
meeting,
]
marks // [2026-05-04, 10:00:00, 2026-05-04T10:00:00, 2026-05-04T10:00:00+02:00[Europe/Paris]]
marks.filter({ x is Time.PlainDate }) // [2026-05-04]Test the member with is to branch on it; after the last test, the remaining member is narrowed too:
func describe(t: Time.Wall): string {
if t is Time.PlainDate {
"a date"
} else if t is Time.PlainTime {
"a clock time"
} else if t is Time.PlainDateTime {
"a date and time"
} else {
"a time in ${t.zoneOf().zoneId()}"
}
}
let meeting = Time.parseZoned("2026-05-04T10:00[Europe/Paris]").unwrap()
let marks: Array[Time.Wall] = [Time.plainDate(2026, 5, 4), Time.plainTime(10, 0), meeting]
for m in marks {
println("${m}: ${describe(m)}")
}2026-05-04: a date
10:00:00: a clock time
2026-05-04T10:00:00+02:00[Europe/Paris]: a time in Europe/ParisGuards narrow a Time.Wall before the main path, so the last line calls Time.with on a ZonedDateTime:
func firstOfMonth(t: Time.Wall): Time.Wall {
if t is Time.PlainTime { return t }
if t is Time.PlainDate { return t.with(day: 1) }
if t is Time.PlainDateTime { return t.with(day: 1) }
t.with(day: 1)
}
println(firstOfMonth(Time.plainDate(2026, 4, 10)))
println(firstOfMonth(Time.plainTime(9, 0)))
let flight = Time.parseZoned("2026-04-10T08:00[Asia/Tokyo]").unwrap()
println(firstOfMonth(flight))2026-04-01
09:00:00
2026-04-01T08:00:00+09:00[Asia/Tokyo]Applications
An agenda keeps all-day dates, daily clock times, and zoned meetings in one list, and renders each entry by its member:
type Item = { title: string, when: Time.Wall }
func label(w: Time.Wall): string {
if w is Time.PlainDate { return "all day ${w}" }
if w is Time.PlainTime { return "daily at ${w}" }
if w is Time.PlainDateTime { return "at ${w}" }
"at ${w.toPlainDateTime()} in ${w.zoneOf().zoneId()}"
}
let day = Time.plainDate(2026, 5, 4)
let standup = Time.parseZoned("2026-05-04T09:30[America/New_York]").unwrap()
let agenda: Array[Item] = [
Item{ title: "Release day", when: day },
Item{ title: "Water the plants", when: Time.plainTime(8, 0) },
Item{ title: "Dentist", when: Time.plainDateTime(day, Time.plainTime(15, 0)) },
Item{ title: "Standup", when: standup },
]
for e in agenda {
println("${e.title}: ${label(e.when)}")
}Release day: all day 2026-05-04
Water the plants: daily at 08:00:00
Dentist: at 2026-05-04T15:00:00
Standup: at 2026-05-04T09:30:00 in America/New_YorkProperties and relations
Time.Wall is Time.Point without Time.Instant, and holds both Time.Dated and Time.Timed, so each assigns where a wider union is expected:
let day: Time.Dated = Time.plainDate(2026, 1, 1)
let alarm: Time.Timed = Time.plainTime(7, 0)
let walls: Array[Time.Wall] = [day, alarm]
let points: Array[Time.Point] = [...walls]
assert(points.length() == 2)Possible issues
A value typed with the union does not pass to Time.with; narrow it first:
let release: Time.Wall = Time.plainDate(2026, 4, 10)
let first = Time.with(release, day: 1)
// error: T would be Time.Wall, which is not a single member of its bound Time.Wall; narrow firstTime.Instant is not a member: it has no fields to replace. Convert it to a ZonedDateTime with Time.inZone first:
let epoch = Time.fromEpochMillis(0)
let later = Time.with(epoch, year: 2000)
// error: T would be Time.Instant, which is not a member of its bound Time.WallA Time.Wall is not a Time.Dated, since a PlainTime has no date:
let release: Time.Wall = Time.plainDate(2026, 4, 10)
let year = Time.year(release) // error: cannot use Time.Wall where Time.Dated is expectedThe bound admits every member, but a PlainDate takes no time fields, so a function bounded by Time.Wall can still panic on one:
func startOfMinute[T: Time.Wall](t: T): T {
Time.with(t, second: 0)
}
let today = startOfMinute(Time.plainDate(2026, 4, 10)) // panic: Time.with: a date has no time fieldsSee also
Time.with · Time.Point · Time.Dated · Time.Timed · Time.PlainDate · Time.PlainTime · Time.PlainDateTime · Time.ZonedDateTime
