TZInfo
(require tzinfo) | package: tzinfo |
1 Introduction
The tzinfo library provides an interface for querying the IANA time zone database (also known as the Olson database).
UNIX systems usually come with a compiled version of the IANA database (typically in /usr/share/zoneinfo). tzinfo will use the system’s database if available. However, if the tzdata package is installed, that will be used instead. Since Windows systems do not come with a zoneinfo database, Windows users must install tzdata to use tzinfo.
2 Querying the Database
procedure
(tzid-exists? tzid) → boolean?
tzid : string?
> (tzid-exists? "Europe/London") #t
> (tzid-exists? "Fillory/Whitespire") #f
procedure
(utc-seconds->tzoffset tzid seconds) → tzoffset?
tzid : string? seconds : real?
> (utc-seconds->tzoffset "America/New_York" 0) (tzoffset -18000 #f "EST")
> (utc-seconds->tzoffset "Fillory/Whitespire" 0) Cannot find zoneinfo file for [Fillory/Whitespire]
procedure
(local-seconds->tzoffset tzid seconds)
→ (or/c tzoffset? tzgap? tzoverlap?) tzid : string? seconds : real?
a tzoffset struct, describing the offset from UTC in effect at the given time in the given time zone;
a tzgap struct if the given local time falls into a gap between different offsets (as, for example, when an hour is skipped at the start of daylight saving time in most parts of the United States); or
a tzoverlap struct if the given local time falls in a period when two different offsets might be in effect (as, for example, at the end of daylight saving time, when an hour is repeated).
Raises exn:fail:tzinfo:zone-not-found if the given time zone ID is not in the database.
> (local-seconds->tzoffset "America/New_York" 1409606993) (tzoffset -14400 #t "EDT")
> (local-seconds->tzoffset "America/New_York" 1394330400) (tzgap 1394348400 (tzoffset -18000 #f "EST") (tzoffset -14400 #t "EDT"))
> (local-seconds->tzoffset "America/New_York" 1414890000) (tzoverlap (tzoffset -14400 #t "EDT") (tzoffset -18000 #f "EST"))
procedure
(tzid->country-codes tzid) → (listof string?)
tzid : string?
> (tzid->country-codes "Europe/Moscow") '("RU")
> (tzid->country-codes "Antarctica/Troll") '("AQ")
> (tzid->country-codes "Africa/Kinshasa") '()
procedure
(country-code->tzids cc) → (listof string?)
cc : string?
> (country-code->tzids "US")
'("America/Yakutat"
"America/Indiana/Tell_City"
"Pacific/Honolulu"
"America/Detroit"
"America/Juneau"
"America/Chicago"
"America/Indiana/Vevay"
"America/Sitka"
"America/Denver"
"America/Anchorage"
"America/Menominee"
"America/Indiana/Winamac"
"America/Nome"
"America/Kentucky/Monticello"
"America/North_Dakota/Center"
"America/Kentucky/Louisville"
"America/North_Dakota/New_Salem"
"America/Indiana/Knox"
"America/Indiana/Indianapolis"
"America/North_Dakota/Beulah"
"America/Indiana/Petersburg"
"America/Metlakatla"
"America/Indiana/Vincennes"
"America/Adak"
"America/Phoenix"
"America/Indiana/Marengo"
"America/Los_Angeles"
"America/Boise"
"America/New_York")
> (country-code->tzids "IT") '("Europe/Rome")
procedure
(system-tzid) → (or/c string? #f)
struct
3 Offsets, Gaps, and Overlaps
struct
(struct tzoffset (utc-seconds dst? abbreviation) #:transparent) utc-seconds : exact-integer? dst? : boolean? abbreviation : string?
struct
(struct tzgap (starts-at offset-before offset-after) #:transparent) starts-at : exact-integer? offset-before : tzoffset? offset-after : tzoffset?
struct
(struct tzoverlap (offset-before offset-after) #:transparent) offset-before : tzoffset? offset-after : tzoffset?
4 Data Sources
tzinfo allows for a pluggable data sources. At present, the only supported source is based on zoneinfo files, which are a compiled form of the IANA database, widely- used on UNIX systems.
parameter
(current-tzinfo-source) → tzinfo-source?
(current-tzinfo-source tzinfo-source) → void? tzinfo-source : tzinfo-source?
= #f
procedure
ctor : (-> tzinfo-source?)
5 Data Source Generics
(require tzinfo/source) | package: tzinfo |
value
gen:tzinfo-source : any/c
tzinfo->all-tzids
tzinfo-has-tzid?
tzinfo-tzid->country-codes
tzinfo-country-code->tzids
seconds->tzoffset/utc
seconds->tzoffset/local
detect-system-tzid
procedure
src : tzinfo-source? tzid : string?
procedure
(seconds->tzoffset/utc src tzid seconds) → tzoffset?
src : tzinfo-source? tzid : string? seconds : real?