Time.zoneId
func Time.zoneId(z: Time.Zone): stringTime.zoneId returns the identifier of z: its name as the database spells it, or its offset as ±HH:MM, with + for a zero offset.
Details
- A name comes back as the database spells it, whatever letter case
Time.zonewas given:asia/tokyogivesAsia/Tokyo. - An alias keeps its own name:
Asia/CalcuttastaysAsia/Calcutta, although it equals the zoneAsia/Kolkata. - An offset comes back as
±HH:MM, whichever formTime.zonewas given. - The identifier is what a zone prints as, and
Time.zoneparses it back to an equal zone.
Basic examples
Time.zoneId(Result.unwrap(Time.zone("asia/calcutta"))) // "Asia/Calcutta"
Time.zoneId(Result.unwrap(Time.zone("+0530"))) // "+05:30"The zone of a zoned time:
let t = Result.unwrap(Time.parseZoned("2026-07-01T12:00[Europe/Stockholm]"))
Time.zoneId(Time.zoneOf(t)) // "Europe/Stockholm"Scope
Names in any letter case come back as the database spells them:
Time.zone("EUROPE/STOCKHOLM").unwrap().zoneId() // "Europe/Stockholm"
Time.zone("us/eastern").unwrap().zoneId() // "US/Eastern"
Time.zone("etc/gmt+5").unwrap().zoneId() // "Etc/GMT+5"Every form of offset comes back as ±HH:MM:
Time.zone("+05:30").unwrap().zoneId() // "+05:30"
Time.zone("-0800").unwrap().zoneId() // "-08:00"
Time.zone("+14").unwrap().zoneId() // "+14:00"Time.utc is the named zone UTC, not an offset:
Time.utc.zoneId() // "UTC"
Time.zone("utc").unwrap().zoneId() // "UTC"In a pipeline, map it over the result of Time.zone:
"america/new_york" | Time.zone() | Result.map(Time.zoneId) // Ok{ value: "America/New_York" }The identifier of the host's zone is a name such as Europe/Stockholm, or an offset such as +02:00 when the host names no zone of the database:
println(Time.localZone().zoneId())Map it over several zones, and join the identifiers:
["Europe/Stockholm", "asia/tokyo", "-0800"]
| Array.map({ Time.zone(x).unwrap() })
| Array.map(Time.zoneId)
| String.join(", ")
// "Europe/Stockholm, Asia/Tokyo, -08:00"Applications
Check a zone that a user typed, and store it in the database's spelling:
func canonicalZone(id: string): Result[string, Error] {
Time.zone(id) | Result.map(Time.zoneId)
}
println(canonicalZone("asia/kolkata"))
println(canonicalZone("Nowhere"))Ok{ value: "Asia/Kolkata" }
Err{ error: Error{ message: "unknown time zone \"Nowhere\"" } }Save a wall-clock time with its zone as text, and restore it later:
let meeting = Time.parseZoned("2026-10-22T09:00[America/New_York]").unwrap()
let saved = ["${meeting.toPlainDateTime()}", meeting.zoneOf().zoneId()]
let zone = Time.zone(saved[1]).unwrap()
let restored = Time.parsePlainDateTime(saved[0]).unwrap().toZoned(zone)
println(restored)
assert(restored == meeting)2026-10-22T09:00:00-04:00[America/New_York]Label the clocks of a team's offices:
let at = Time.parseInstant("2026-07-01T12:00:00Z").unwrap()
for id in ["America/Los_Angeles", "Asia/Tokyo", "+05:45"] {
let local = at.inZone(Time.zone(id).unwrap())
println("${local.zoneOf().zoneId()}: ${local.toPlainTime()}")
}America/Los_Angeles: 05:00:00
Asia/Tokyo: 21:00:00
+05:45: 17:45:00Properties and relations
The identifier parses back to an equal zone, and it is the text a zone prints as:
for id in ["Europe/Paris", "asia/calcutta", "-0330", "UTC"] {
let zone = Time.zone(id).unwrap()
assert(Time.zone(zone.zoneId()).unwrap() == zone)
assert("${zone}" == zone.zoneId())
}For an offset zone, the identifier is the offset of every time in it:
let zone = Time.zone("+0530").unwrap()
let t = Time.parseInstant("2026-01-15T12:00:00Z").unwrap().inZone(zone)
assert(t.offset() == zone.zoneId())Possible issues
Two aliases are equal zones with different identifiers, so compare zones, not identifiers:
let calcutta = Time.zone("Asia/Calcutta").unwrap()
let kolkata = Time.zone("Asia/Kolkata").unwrap()
calcutta == kolkata // true
calcutta.zoneId() == kolkata.zoneId() // falseTime.utc and the offset zone +00:00 have the same offset but are different zones, with different identifiers:
Time.utc == Time.zone("+00:00").unwrap() // false
Time.zone("+00:00").unwrap().zoneId() // "+00:00"The identifier of a named zone is not its offset. Use Time.offset on a zoned time for that:
let t = Time.parseZoned("2026-07-01T12:00[Asia/Tokyo]").unwrap()
t.zoneOf().zoneId() // "Asia/Tokyo"
t.offset() // "+09:00"Time.zoneId takes a Time.Zone, not a zoned time or a string:
let t = Time.parseZoned("2026-07-01T12:00[Asia/Tokyo]").unwrap()
println(Time.zoneId(t))
// error: cannot use Time.ZonedDateTime where Time.Zone is expected
println(Time.zoneId("Asia/Tokyo"))
// error: cannot use string where Time.Zone is expectedSee also
Time.zone · Time.zoneOf · Time.localZone · Time.offset · Time.inZone · Time.Zone
