On this page:
Zoned  Date  Time
Zoned  Date  Time.year
Zoned  Date  Time.month
Zoned  Date  Time.day
Zoned  Date  Time.hour
Zoned  Date  Time.minute
Zoned  Date  Time.second
Zoned  Date  Time.nanosecond
Zoned  Date  Time.is_  dst
Zoned  Date  Time.time_  zone_  offset
Zoned  Date  Time.time_  zone_  name
Zoned  Date  Time.week_  day
Zoned  Date  Time.year_  day
Zoned  Date  Time.now
Zoned  Date  Time.from_  seconds
Zoned  Date  Time.to_  string
Zoned  Date  Time.to_  seconds

14.7.4 Date and Time in a Time Zone🔗ℹ

class

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.

property

property (dt :: date.ZonedDateTime).week_day :: Int.in(0 ..= 6)

 

property

property (dt :: date.ZonedDateTime).year_day :: Int.in(0 ..= 366)

Reports a day of the week or day of the year represented by dt.

function

fun date.ZonedDateTime.now(~local: local :: Any = #true) :: date.DateTime

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.

function

fun date.ZonedDateTime.from_seconds(

  secs :: Real,

  ~local: local :: Any = #true

) :: date.TimeDate

Like date.DateTime.from_seconds, but preserving the time zone selected by local and (if true) the current time zone.

> date.ZonedDateTime.from_seconds(0, ~local: #false)

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

)

method

method (dt :: date.ZonedDateTime).to_string(

  ~format: format :: date.Format = #'rfc3339,

  ~time_format: time_format :: maybe(date.TimeFormat) = #'seconds,

  ~time_zone_format: tz_format :: maybe(date.TimeZoneFormat) = #'offset

) :: String

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")

> dt1.to_string()

"1968-01-24 00:00:10+07:00"

> dt1.to_string(~format: #'rfc2822)

"Wed, 24 Jan 1968 00:00:10 +0700"

method

method (dt :: date.ZonedDateTime).to_seconds() :: Real

Returns the number of seconds since the epoch until dt.