7.7
16 Time Zones and UTC Offsets
A time zone, in Gregor, is either:
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.
A parameter that defines the current time zone. The current time zone is used
as a default value in many Gregor functions, including
moment and
all of the
clock functions that rely on the current moment.
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
Constructs an
offset resolver from the given
gap-resolver and
overlap-resolver.
Examples:
|
Illegal moment: local time 2015-03-08T02:30:00 does not |
exist in time zone America/New_York |
|
Illegal moment: local time 2015-11-01T01:30:00 is ambiguous |
in time zone America/New_York |
Examples:
|
#<moment 2015-03-08T01:59:59.999999999-05:00[America/New_York]> |
|
#<moment 2015-11-01T01:30:00-04:00[America/New_York]> |
Examples:
|
#<moment 2015-03-08T03:00:00-04:00[America/New_York]> |
|
#<moment 2015-11-01T01:30:00-05:00[America/New_York]> |
Examples:
|
#<moment 2015-03-08T03:00:00-04:00[America/New_York]> |
|
#<moment 2015-11-01T01:30:00-04:00[America/New_York]> |
This resolver is used by default in date arithmetic functions.
Examples:
|
#<moment 2015-11-01T01:30:00-04:00[America/New_York]> |
|
#<moment 2015-11-01T01:30:00-05:00[America/New_York]> |
Examples:
|
#<moment 2015-03-08T03:30:00-04:00[America/New_York]> |
|
#<moment 2015-11-01T01:30:00-05:00[America/New_York]> |
16.1.2 Gap Resolvers
A contract for
gap resolver functions. The contract is specified as:
Returns the
moment just prior to the given
gap.
Returns the
moment at the end of the given
gap.
Returns a
moment where the
local datetime portion is pushed
forward by the length of the gap.
16.1.3 Overlap Resolvers
Returns a
moment for the given
local datetime, using the
UTC offset in effect before the overlap.
Returns a
moment for the given
local datetime, using the
UTC offset in effect after the overlap.
If
orig is a
moment and its UTC offset is one of the ones involved
in the given
overlap, then the result will use that offset. Otherwise, this
function behaves the same as
resolve-overlap/post.