16 Time Zones and UTC Offsets
value
tz/c : flat-contract?
an identifier from the IANA tz database, like "America/New_York" or "Antarctica/Troll", or
an offset from UTC in seconds, expressed as an exact integer between -64800 and 64800.
parameter
(current-timezone) → tz/c
(current-timezone tz) → void? tz : tz/c
= (system-tzid)
16.1 Resolving UTC Offsets
Many time zones introduce discontinuities in the local time-line. In time zones that use daylight saving time (DST), the transition from standard time to DST introduces a gap in the time-line when the local time jumps ahead by an hour. Similarly, the transition back to standard time introduces an overlap when the clock is set back and the same hour is repeated, only with a different UTC offset.
Whenever a Gregor function might construct a moment that falls into a gap or an overlap, the function will accept an optional keyword argument named #:resolve-offset. The argument value must be an offset resolver, a function satisfying the offset-resolver/c contract.
An offset resolver comprises a gap resolver and an overlap resolver, functions that satisfy gap-resolver/c and overlap-resolver/c, respectively.
Most functions that take a #:resolve-offset parameter use resolve-offset/raise as the default value. This is a simple offset resolver that raises exn:gregor:invalid-offset whenever it encounters either a gap or an overlap.
16.1.1 Offset Resolvers
value
offset-resolver/c : chaperone-contract?
procedure
(offset-resolver gap-resolver overlap-resolver) → offset-resolver/c gap-resolver : gap-resolver/c overlap-resolver : overlap-resolver/c
procedure
(resolve-offset/raise gap-or-overlap local tzid orig) → moment? gap-or-overlap : (or/c tzgap? tzoverlap?) local : datetime? tzid : string? orig : (or/c moment? #f)
> (moment 2015 3 8 2 30 #:tz "America/New_York" ; in gap #:resolve-offset resolve-offset/raise) Illegal moment: local time 2015-03-08T02:30:00 does not
exist in time zone America/New_York
> (moment 2015 11 1 1 30 #:tz "America/New_York" ; in overlap #:resolve-offset resolve-offset/raise) Illegal moment: local time 2015-11-01T01:30:00 is ambiguous
in time zone America/New_York
procedure
(resolve-offset/pre gap-or-overlap local tzid orig) → moment? gap-or-overlap : (or/c tzgap? tzoverlap?) local : datetime? tzid : string? orig : (or/c moment? #f)
> (moment 2015 3 8 2 30 #:tz "America/New_York" ; in gap #:resolve-offset resolve-offset/pre) #<moment 2015-03-08T01:59:59.999999999-05:00[America/New_York]>
> (moment 2015 11 1 1 30 #:tz "America/New_York" ; in overlap #:resolve-offset resolve-offset/pre) #<moment 2015-11-01T01:30:00-04:00[America/New_York]>
procedure
(resolve-offset/post gap-or-overlap local tzid orig) → moment? gap-or-overlap : (or/c tzgap? tzoverlap?) local : datetime? tzid : string? orig : (or/c moment? #f)
> (moment 2015 3 8 2 30 #:tz "America/New_York" ; in gap #:resolve-offset resolve-offset/post) #<moment 2015-03-08T03:00:00-04:00[America/New_York]>
> (moment 2015 11 1 1 30 #:tz "America/New_York" ; in overlap #:resolve-offset resolve-offset/post) #<moment 2015-11-01T01:30:00-05:00[America/New_York]>
procedure
(resolve-offset/post-gap/pre-overlap gap-or-overlap local tzid orig) → moment? gap-or-overlap : (or/c tzgap? tzoverlap?) local : datetime? tzid : string? orig : (or/c moment? #f)
> (moment 2015 3 8 2 30 #:tz "America/New_York" ; in gap #:resolve-offset resolve-offset/post-gap/pre-overlap) #<moment 2015-03-08T03:00:00-04:00[America/New_York]>
> (moment 2015 11 1 1 30 #:tz "America/New_York" ; in overlap #:resolve-offset resolve-offset/post-gap/pre-overlap) #<moment 2015-11-01T01:30:00-04:00[America/New_York]>
procedure
(resolve-offset/retain gap-or-overlap local tzid orig) → moment? gap-or-overlap : (or/c tzgap? tzoverlap?) local : datetime? tzid : string? orig : (or/c moment? #f)
This resolver is used by default in date arithmetic functions.
> (+years (moment 2014 11 1 1 30 #:tz "America/New_York") ; UTC-04:00 1 #:resolve-offset resolve-offset/retain) #<moment 2015-11-01T01:30:00-05:00[America/New_York]>
> (+years (moment 2014 11 1 1 30 #:tz "America/New_York") ; UTC-04:00 1 #:resolve-offset resolve-offset/post) #<moment 2015-11-01T01:30:00-05:00[America/New_York]>
procedure
(resolve-offset/push gap-or-overlap local tzid orig) → moment? gap-or-overlap : (or/c tzgap? tzoverlap?) local : datetime? tzid : string? orig : (or/c moment? #f)
> (moment 2015 3 8 2 30 #:tz "America/New_York" ; in gap #:resolve-offset resolve-offset/push) #<moment 2015-03-08T03:30:00-04:00[America/New_York]>
> (moment 2015 11 1 1 30 #:tz "America/New_York" ; in overlap #:resolve-offset resolve-offset/push) #<moment 2015-11-01T01:30:00-05:00[America/New_York]>
16.1.2 Gap Resolvers
value
gap-resolver/c : chaperone-contract?
procedure
(resolve-gap/pre gap local tzid orig) → moment?
gap : tzgap? local : datetime? tzid : string? orig : (or/c moment? #f)
procedure
(resolve-gap/post gap local tzid orig) → moment?
gap : tzgap? local : datetime? tzid : string? orig : (or/c moment? #f)
procedure
(resolve-gap/push gap local tzid orig) → moment?
gap : tzgap? local : datetime? tzid : string? orig : (or/c moment? #f)
16.1.3 Overlap Resolvers
value
overlap-resolver/c : chaperone-contract?
(-> tzoverlap? datetime? string? (or/c moment? #f) moment?)
procedure
(resolve-overlap/pre overlap local tzid orig) → moment?
overlap : tzoverlap? local : datetime? tzid : string? orig : (or/c moment? #f)
procedure
(resolve-overlap/post overlap local tzid orig) → moment? overlap : tzoverlap? local : datetime? tzid : string? orig : (or/c moment? #f)
procedure
(resolve-overlap/retain overlap local tzid orig) → moment? overlap : tzoverlap? local : datetime? tzid : string? orig : (or/c moment? #f)