14.7.4 Date and Time in a Time Zone🔗ℹ
|
class date.ZonedDateTime( | ~year: year :: Int, | ~month: month :: Int.in(1 ..= 12) = 1, | ~day: day :: Int.in(1 ..= date.days_in_month(year, month)) = 1, | ~hour: hour :: Int.in(0 ..= 23) = 0, | ~minute: minute :: Int.in(0 ..= 59) = 0, | ~second: second :: Int.in(0 ..= 60) = 0, | ~nanosecond: nanosecond :: Int.in(0 ..= 999_999_999) = 0, | ~is_dst: is_dst :: Boolean = #false, | ~time_zone_offset: time_zone_offset :: Int = 0, | ~time_zone_name: time_zone_name :: String = "UTC" | ) |
|
Represents an absolute date and time within a specific time zone. The
time_zone_offset argument is in seconds. There is no checking
that
time_zone_offset,
is_dst, and and
time_zone_name are consistent, but they will be filled in
correctly when a function like
date.ZonedDateTime.now
date.ZonedDateTime.from_seconds is used to create a
date.ZonedDateTime.
Unlike date.DateTime,
date.ZonedDateTime accommodates a leap second. There
is no checking when a date.ZonedDateTime is created
that the leap second is appropriate to the date.
The date.ZonedDateTime class privately implements
Comparable, so date.ZonedDateTime
instances can be compared with operators like < and
>. Comparison involves conversion via
date.ZonedDateTime.to_seconds.
A date.ZonedDateTime instance is serializable.
Reports a day of the week or day of the year represented by
dt.
Like
date.DateTime.now, but preserving the time zone selected
by
local and (if true) the current time zone, and with a leap
second (if any) preserved.
Like
date.DateTime.from_seconds, but preserving the time zone
selected by
local and (if true) the current time zone.
|
ZonedDateTime( |
~year: 1970, |
~month: 1, |
~day: 1, |
~hour: 0, |
~minute: 0, |
~second: 0, |
~nanosecond: 0, |
~time_zone_offset: 0, |
~time_zone_name: "UTC", |
~is_dst: #false |
) |
Converts
dt to a string in a similar way as
date.DateTime.to_string, but with an extra option
tz_format to determine whether a time zone is shown if
it is optional for
format.
> def dt1 = date.ZonedDateTime(~year: 1968, ~month: 1, ~day: 24, ~second: 10, | ~time_zone_offset: 7 * 60 * 60, | ~time_zone_name: "MDT") |
|
|
"1968-01-24 00:00:10+07:00" |
|
"Wed, 24 Jan 1968 00:00:10 +0700" |
Returns the number of seconds since
the epoch until
dt.