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, tzdata will automatically be installed on Windows systems when tzinfo is installed.
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/Indiana/Indianapolis"
"America/Detroit"
"America/Nome"
"America/Indiana/Vincennes"
"America/Adak"
"America/Sitka"
"America/North_Dakota/New_Salem"
"America/Indiana/Petersburg"
"America/Los_Angeles"
"America/Indiana/Winamac"
"America/Indiana/Marengo"
"America/New_York"
"America/North_Dakota/Beulah"
"America/Indiana/Knox"
"America/Denver"
"America/Phoenix"
"America/Juneau"
"America/Chicago"
"America/North_Dakota/Center"
"America/Boise"
"America/Kentucky/Monticello"
"America/Indiana/Tell_City"
"Pacific/Honolulu"
"America/Metlakatla"
"America/Anchorage"
"America/Indiana/Vevay"
"America/Menominee"
"America/Yakutat"
"America/Kentucky/Louisville")
> (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?)
struct
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?
6 Building standalone executables that use tzinfo
If you build a standalone executable (with raco exe) that uses this library, you should keep in mind where you intend to deploy it. Most UNIX / MacOS systems come with the zoneinfo database installed, but Windows systems do not, nor do some minimal UNIX systems.
To ensure that the target system will be able to find and use zoneinfo files, wherever you deploy your executable, you should install the tzdata package. (When you install tzinfo on a Windows system, tzdata is automatically installed.) If tzdata is installed, the zoneinfo files will be bundled with your executable when you use raco distribute.