5.44. kink/datetime/TIMEZONE¶
Provides timezone type.
5.44.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.
5.44.1.1. Tz.name¶
“name” method returns the name of Tz, such as "Asia/Tokyo".
5.44.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.
5.44.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.
5.44.1.4. Tz.repr¶
`repr` returns a str representation of `Tz`, such as "(timezone Asia/Tokyo)".
5.44.1.5. Tz1 == Tz2¶
Two timezone values are equal when they have the same name.
5.44.2. TIMEZONE.for(Name ...[$config={}])¶
`for` tries to find a timezone specified by `Name`, from the timezone repository provided by the runtime.
Config methods:
• C.on_success($success): default = VAL.identity
• C.on_error($error): default = a fun which raises an exception
If the timezone is found, `for` tail-calls $success with the timezone.
If no timezone is found, `for` tail-calls $error with no arg.
Preconditions
• `Name` must be a str.
• $success must be a fun which takes a `timezone` val.
• $error must be a fun which takes 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 not found: "No/Such_Tz"
Example
:TIMEZONE.require_from('kink/datetime/')
:CONTROL.require_from('kink/')
TIMEZONE.for('Asia/Tokyo'){(:C)
C.on_success{(:Tz) stdout.print_line(Tz.repr) }
}
# => (timezone Asia/Tokyo)
TIMEZONE.for('No/Such_Tz'){(:C)
C.on_error{() stdout.print_line('no such tz') }
}
# => no such tz
5.44.3. TIMEZONE.is?(Val)¶
TIMEZONE.is? returns whether Val is a timezone.
5.44.4. TIMEZONE.default¶
“default” fun returns the runtime-default timezone.