4.42. kink/datetime/TIMEZONE

Provides timezone type.

4.42.1. type timezone

A timezone represents the rule of transition of UTC offset in a specific region.

The set of timezones are provided by the runtime.

4.42.1.1. Tz.name

“name” method returns the name of Tz, such as "Asia/Tokyo".

4.42.1.2. Tz.offset_for_instant(Instant)

`offset_for_instant` returns the `offset` valid in the timezone at `Instant`.

Precondition:

• Instant must be an instant.

4.42.1.3. Tz.offset_for_datetime(Datetime $single_cont $overlap_cont $gap_cont)

`offset_for_datetime` produces the `offset`, or the pair of `offset` vals, valid in the timezone at `Datetime`.

Precondition:

• `Datetime` must be `datetime`

Result:

• If there is only one `offset` valid at `Datetime`, `offset_for_datetime` tail-calls $single_cont with the `offset`.

• If there are two `offset` vals valid at `Datetime` due to transition, `offset_for_datetime` tail-calls $overlap_cont with the offset before the transition, and the offset after the transition.

• If there is no `offset` valid at `Datetime` due to transition, `offset_for_datetime` tail-calls $gap_cont with the offset before the transition, and the offset after the transition.

4.42.1.4. Tz.repr

`repr` returns a str representation of `Tz`, such as "(timezone Asia/Tokyo)".

4.42.1.5. Tz1 == Tz2

Two timezone values are equal when they have the same name.

4.42.2. TIMEZONE.for(Name ...[$config])

“for” tries to find the timezone specified by Name.

The fun searches the repository of timezones provided by the runtime.

Preconditions:

• Name must be a str

• $config, if specified, must be a fun which takes a conf val.

The conf val provides the following methods:

• C.on_present($present_cont) : uses $present_cont as the present cont. If the method is not called, VAL.identity is used as the default present cont.

• C.on_absent($absent_cont) : uses $absent_cont as the absent cont. If the method is not called, the default absent cont raises an exception when the timezone is not found.

Result:

• If the timezone is found, “for” tail-calls the present cont with the timezone.

• If the timezone is not found, “for” tail-calls the absent cont with no arg.

Example:

:TIMEZONE.require_from('kink/datetime/')
:CONTROL.require_from('kink/')

stdout.print_line(TIMEZONE.for('Asia/Tokyo').repr) # => Timezone(Asia/Tokyo)

CONTROL.try(
  { TIMEZONE.for('No/Such_Tz') }
  { raise('doesn''t reach here') }
  {(:Exc) stdout.print_line(Exc.message) }
)
# => TIMEZONE.for(Name ...$config): timezone not found: "No/Such_Tz"

Example specifying continuations:

:TIMEZONE.require_from('kink/datetime/')
:CONTROL.require_from('kink/')

TIMEZONE.for('Asia/Tokyo'){(:C)
  C.on_present{(:Tz) stdout.print_line(Tz.repr) }
}
# => Timezone(Asia/Tokyo)

TIMEZONE.for('No/Such_Tz'){(:C)
  C.on_absent{() stdout.print_line('no such tz') }
}
# => no such tz

4.42.3. TIMEZONE.is?(Val)

TIMEZONE.is? returns whether Val is a timezone.

4.42.4. TIMEZONE.default

“default” fun returns the runtime-default timezone.