JS.Temporal.ZonedDateTime
- Package
- purescript-js-temporal
- Repository
- pete-murphy/purescript-js-temporal
A date and time with time zone, representing a unique instant plus a time zone and calendar. Use when you need an absolute point in time with human-readable components in a specific zone.
#ZonedDateTimeComponents Source
type ZonedDateTimeComponents :: Row Typetype ZonedDateTimeComponents = (calendar :: String, day :: Int, era :: String, eraYear :: Int, hour :: Int, microsecond :: Int, millisecond :: Int, minute :: Int, month :: Int, monthCode :: String, nanosecond :: Int, offset :: String, second :: Int, timeZone :: String, year :: Int)
#fromWithOptions Source
fromWithOptions :: forall optsProvided provided rest. Union provided rest ZonedDateTimeComponents => ConvertOptionsWithDefaults ToFromOptions (Record FromOptions) (Record optsProvided) (Record FromOptions) => Record optsProvided -> Record provided -> Effect ZonedDateTimeCreates a ZonedDateTime from component fields. Options: overflow, disambiguation, offset.
exampleFromWithOptions :: Effect Unit
exampleFromWithOptions = do
zoned <- ZonedDateTime.fromWithOptions { overflow: Overflow.Constrain }
{ year: 2024, month: 1, day: 15, hour: 12, minute: 0, second: 0, timeZone: "America/New_York" }
Console.log (ZonedDateTime.toString zoned)
2024-01-15T12:00:00-05:00[America/New_York]
#from Source
from :: forall provided rest. Union provided rest ZonedDateTimeComponents => Record provided -> Effect ZonedDateTimeSame as fromWithOptions with default options.
exampleFrom :: Effect Unit
exampleFrom = do
zoned <- ZonedDateTime.from
{ year: 2024, month: 1, day: 15, hour: 12, minute: 0, second: 0, timeZone: "America/New_York" }
Console.log (ZonedDateTime.toString zoned)
2024-01-15T12:00:00-05:00[America/New_York]
#fromStringWithOptions Source
fromStringWithOptions :: forall provided. ConvertOptionsWithDefaults ToFromOptions (Record FromOptions) (Record provided) (Record FromOptions) => Record provided -> String -> Effect ZonedDateTimeParses an ISO 8601 string with time zone (e.g. "2024-01-15T12:00-05:00[America/New_York]"). Options: overflow, disambiguation, offset.
exampleFromStringWithOptions :: Effect Unit
exampleFromStringWithOptions = do
zoned <- ZonedDateTime.fromStringWithOptions { overflow: Overflow.Constrain } "2024-01-15T12:00:00-05:00[America/New_York]"
Console.log (ZonedDateTime.toString zoned)
2024-01-15T12:00:00-05:00[America/New_York]
#fromString Source
fromString :: String -> Effect ZonedDateTimeSame as fromStringWithOptions with default options.
exampleFromString :: Effect Unit
exampleFromString = do
zoned <- ZonedDateTime.fromString "1970-01-01T00:00:00+00:00[UTC]"
Console.log (ZonedDateTime.toString zoned)
1970-01-01T00:00:00+00:00[UTC]
#year Source
year :: ZonedDateTime -> IntCalendar year in this zoned date-time's calendar.
exampleYear :: Effect Unit
exampleYear = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Year: " <> show (ZonedDateTime.year zoned))
Year: 2024
#month Source
month :: ZonedDateTime -> IntCalendar month number in this zoned date-time's calendar.
exampleMonth :: Effect Unit
exampleMonth = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Month: " <> show (ZonedDateTime.month zoned))
Month: 7
#day Source
day :: ZonedDateTime -> IntDay of the month in this zoned date-time's calendar.
exampleDay :: Effect Unit
exampleDay = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Day: " <> show (ZonedDateTime.day zoned))
Day: 1
#monthCode Source
monthCode :: ZonedDateTime -> StringCalendar-specific month code (for example "M01").
exampleMonthCode :: Effect Unit
exampleMonthCode = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Month code: " <> ZonedDateTime.monthCode zoned)
Month code: M07
#hour Source
hour :: ZonedDateTime -> IntHour of the day in the zoned wall-clock view.
exampleHour :: Effect Unit
exampleHour = do
zoned <- ZonedDateTime.fromString "2024-07-01T14:30:00[America/New_York]"
Console.log ("Hour: " <> show (ZonedDateTime.hour zoned))
Hour: 14
#minute Source
minute :: ZonedDateTime -> IntMinute of the hour in the zoned wall-clock view.
exampleMinute :: Effect Unit
exampleMinute = do
zoned <- ZonedDateTime.fromString "2024-07-01T14:30:00[America/New_York]"
Console.log ("Minute: " <> show (ZonedDateTime.minute zoned))
Minute: 30
#second Source
second :: ZonedDateTime -> IntSecond of the minute in the zoned wall-clock view.
exampleSecond :: Effect Unit
exampleSecond = do
zoned <- ZonedDateTime.fromString "2024-07-01T14:30:45[America/New_York]"
Console.log ("Second: " <> show (ZonedDateTime.second zoned))
Second: 45
#millisecond Source
millisecond :: ZonedDateTime -> IntMillisecond of the second in the zoned wall-clock view.
exampleMillisecond :: Effect Unit
exampleMillisecond = do
zoned <- ZonedDateTime.fromString "2024-07-01T14:30:45.123[America/New_York]"
Console.log ("Millisecond: " <> show (ZonedDateTime.millisecond zoned))
Millisecond: 123
#microsecond Source
microsecond :: ZonedDateTime -> IntMicrosecond of the millisecond in the zoned wall-clock view.
exampleMicrosecond :: Effect Unit
exampleMicrosecond = do
zoned <- ZonedDateTime.fromString "2024-07-01T14:30:45.123456[America/New_York]"
Console.log ("Microsecond: " <> show (ZonedDateTime.microsecond zoned))
Microsecond: 456
#nanosecond Source
nanosecond :: ZonedDateTime -> IntNanosecond of the microsecond in the zoned wall-clock view.
exampleNanosecond :: Effect Unit
exampleNanosecond = do
zoned <- ZonedDateTime.fromString "2024-07-01T14:30:45.123456789[America/New_York]"
Console.log ("Nanosecond: " <> show (ZonedDateTime.nanosecond zoned))
Nanosecond: 789
#dayOfWeek Source
dayOfWeek :: ZonedDateTime -> IntISO day of week, from 1 (Monday) to 7 (Sunday).
exampleDayOfWeek :: Effect Unit
exampleDayOfWeek = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Day of week: " <> show (ZonedDateTime.dayOfWeek zoned))
Day of week: 1
#dayOfYear Source
dayOfYear :: ZonedDateTime -> IntDay number within the year in this zoned date-time's calendar.
exampleDayOfYear :: Effect Unit
exampleDayOfYear = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Day of year: " <> show (ZonedDateTime.dayOfYear zoned))
Day of year: 183
#weekOfYear Source
weekOfYear :: ZonedDateTime -> Maybe IntWeek number within the year, if the calendar defines week numbering.
exampleWeekOfYear :: Effect Unit
exampleWeekOfYear = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Week of year: " <> show (ZonedDateTime.weekOfYear zoned))
Week of year: (Just 27)
#yearOfWeek Source
yearOfWeek :: ZonedDateTime -> Maybe IntWeek-numbering year, if the calendar defines week numbering.
exampleYearOfWeek :: Effect Unit
exampleYearOfWeek = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Year of week: " <> show (ZonedDateTime.yearOfWeek zoned))
Year of week: (Just 2024)
#daysInMonth Source
daysInMonth :: ZonedDateTime -> IntNumber of days in the current month.
exampleDaysInMonth :: Effect Unit
exampleDaysInMonth = do
zoned <- ZonedDateTime.fromString "2024-02-01T12:00:00[America/New_York]"
Console.log ("Days in Feb 2024: " <> show (ZonedDateTime.daysInMonth zoned))
Days in Feb 2024: 29
#daysInYear Source
daysInYear :: ZonedDateTime -> IntNumber of days in the current year.
exampleDaysInYear :: Effect Unit
exampleDaysInYear = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Days in 2024: " <> show (ZonedDateTime.daysInYear zoned))
Days in 2024: 366
#daysInWeek Source
daysInWeek :: ZonedDateTime -> IntNumber of days in the current week according to the calendar.
exampleDaysInWeek :: Effect Unit
exampleDaysInWeek = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Days in week: " <> show (ZonedDateTime.daysInWeek zoned))
Days in week: 7
#monthsInYear Source
monthsInYear :: ZonedDateTime -> IntNumber of months in the current year.
exampleMonthsInYear :: Effect Unit
exampleMonthsInYear = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Months in year: " <> show (ZonedDateTime.monthsInYear zoned))
Months in year: 12
#inLeapYear Source
inLeapYear :: ZonedDateTime -> BooleanWhether the current year is a leap year in this calendar.
exampleInLeapYear :: Effect Unit
exampleInLeapYear = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("2024 is leap year: " <> show (ZonedDateTime.inLeapYear zoned))
2024 is leap year: true
#calendarId Source
calendarId :: ZonedDateTime -> StringIdentifier of the current calendar (for example "iso8601").
exampleCalendarId :: Effect Unit
exampleCalendarId = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Calendar: " <> ZonedDateTime.calendarId zoned)
Calendar: iso8601
#era Source
era :: ZonedDateTime -> Maybe StringCalendar era name, if this calendar uses eras.
exampleEra :: Effect Unit
exampleEra = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Era: " <> show (ZonedDateTime.era zoned))
Era: Nothing
#eraYear Source
eraYear :: ZonedDateTime -> Maybe IntYear number within the current era, if this calendar uses eras.
exampleEraYear :: Effect Unit
exampleEraYear = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Era year: " <> show (ZonedDateTime.eraYear zoned))
Era year: Nothing
#timeZoneId Source
timeZoneId :: ZonedDateTime -> StringIdentifier of the associated time zone (for example "America/New_York").
exampleTimeZoneId :: Effect Unit
exampleTimeZoneId = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Time zone: " <> ZonedDateTime.timeZoneId zoned)
Time zone: America/New_York
#offset Source
offset :: ZonedDateTime -> StringNumeric UTC offset string for this instant in the associated time zone.
exampleOffset :: Effect Unit
exampleOffset = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Offset: " <> ZonedDateTime.offset zoned)
Offset: -04:00
#offsetNanoseconds Source
offsetNanoseconds :: ZonedDateTime -> NumberUTC offset for this instant, in nanoseconds.
exampleOffsetNanoseconds :: Effect Unit
exampleOffsetNanoseconds = do
zoned <- ZonedDateTime.fromString "2024-07-01T12:00:00[America/New_York]"
Console.log ("Offset ns: " <> show (ZonedDateTime.offsetNanoseconds zoned))
Offset ns: -14400000000000.0
#hoursInDay Source
hoursInDay :: ZonedDateTime -> IntNumber of wall-clock hours in this calendar day in the associated time zone.
exampleHoursInDay :: Effect Unit
exampleHoursInDay = do
zoned <- ZonedDateTime.fromString "2024-03-10T12:00:00[America/New_York]"
Console.log ("Hours in day (DST spring forward): " <> show (ZonedDateTime.hoursInDay zoned))
Hours in day (DST spring forward): 23
#epochMilliseconds Source
epochMilliseconds :: ZonedDateTime -> NumberMilliseconds since the Unix epoch for the represented instant.
exampleEpochMilliseconds :: Effect Unit
exampleEpochMilliseconds = do
zoned <- ZonedDateTime.fromString "1970-01-01T00:00:01+00:00[UTC]"
Console.log ("Epoch ms: " <> show (ZonedDateTime.epochMilliseconds zoned))
Epoch ms: 1000.0
#epochNanoseconds Source
epochNanoseconds :: ZonedDateTime -> BigIntNanoseconds since the Unix epoch for the represented instant.
exampleEpochNanoseconds :: Effect Unit
exampleEpochNanoseconds = do
zoned <- ZonedDateTime.fromString "1970-01-01T00:00:01+00:00[UTC]"
Console.log ("Epoch ns: " <> show (ZonedDateTime.epochNanoseconds zoned))
Epoch ns: 1000000000
#addWithOptions Source
addWithOptions :: forall provided. ConvertOptionsWithDefaults ToArithmeticOptions (Record ArithmeticOptions) (Record provided) (Record ArithmeticOptions) => Record provided -> Duration -> ZonedDateTime -> Effect ZonedDateTimeAdds a duration. Supports calendar durations. Options: overflow.
exampleAddWithOptions :: Effect Unit
exampleAddWithOptions = do
start <- ZonedDateTime.fromString "2024-01-15T12:00:00-05:00[America/New_York]"
twoHours <- Duration.from { hours: 2 }
later <- ZonedDateTime.addWithOptions { overflow: Overflow.Constrain } twoHours start
Console.log (ZonedDateTime.toString later)
2024-01-15T14:00:00-05:00[America/New_York]
#add Source
add :: Duration -> ZonedDateTime -> Effect ZonedDateTimeSame as addWithOptions with default options.
exampleAdd :: Effect Unit
exampleAdd = do
start <- ZonedDateTime.fromString "2024-01-15T12:00:00-05:00[America/New_York]"
twoHours <- Duration.from { hours: 2 }
later <- ZonedDateTime.add twoHours start
Console.log (ZonedDateTime.toString later)
2024-01-15T14:00:00-05:00[America/New_York]
#subtractWithOptions Source
subtractWithOptions :: forall provided. ConvertOptionsWithDefaults ToArithmeticOptions (Record ArithmeticOptions) (Record provided) (Record ArithmeticOptions) => Record provided -> Duration -> ZonedDateTime -> Effect ZonedDateTimeSubtracts a duration. Arg order: subtractWithOptions options duration subject.
exampleSubtractWithOptions :: Effect Unit
exampleSubtractWithOptions = do
zoned <- ZonedDateTime.fromString "2024-03-15T14:00:00[America/New_York]"
twoHours <- Duration.from { hours: 2 }
earlier <- ZonedDateTime.subtractWithOptions { overflow: Overflow.Constrain } twoHours zoned
Console.log (ZonedDateTime.toString earlier)
2024-03-15T12:00:00-04:00[America/New_York]
#subtract Source
subtract :: Duration -> ZonedDateTime -> Effect ZonedDateTimeSame as subtractWithOptions with default options.
exampleSubtract :: Effect Unit
exampleSubtract = do
zoned <- ZonedDateTime.fromString "2024-03-15T14:00:00[America/New_York]"
twoHours <- Duration.from { hours: 2 }
earlier <- ZonedDateTime.subtract twoHours zoned
Console.log (ZonedDateTime.toString earlier)
2024-03-15T12:00:00-04:00[America/New_York]
#withWithOptions Source
withWithOptions :: forall optsProvided fields rest. Union fields rest WithFields => ConvertOptionsWithDefaults ToFromOptions (Record FromOptions) (Record optsProvided) (Record FromOptions) => Record optsProvided -> Record fields -> ZonedDateTime -> Effect ZonedDateTimeReturns a copy with some wall-clock fields replaced. Options: overflow, disambiguation, offset.
exampleWithWithOptions :: Effect Unit
exampleWithWithOptions = do
meeting <- ZonedDateTime.fromString "2024-01-15T09:30:45-05:00[America/New_York]"
noon <- ZonedDateTime.withWithOptions { overflow: Overflow.Constrain } { hour: 12, minute: 0, second: 0 } meeting
Console.log (ZonedDateTime.toString noon)
2024-01-15T12:00:00-05:00[America/New_York]
#with Source
with :: forall fields rest. Union fields rest WithFields => Record fields -> ZonedDateTime -> Effect ZonedDateTimeSame as withWithOptions with default options.
exampleWith :: Effect Unit
exampleWith = do
meeting <- ZonedDateTime.fromString "2024-01-15T09:30:45-05:00[America/New_York]"
noon <- ZonedDateTime.with { hour: 12, minute: 0, second: 0 } meeting
Console.log (ZonedDateTime.toString noon)
2024-01-15T12:00:00-05:00[America/New_York]
#withTimeZone Source
withTimeZone :: String -> ZonedDateTime -> Effect ZonedDateTimeReturns the same instant interpreted in a different time zone.
exampleWithTimeZone :: Effect Unit
exampleWithTimeZone = do
zoned <- ZonedDateTime.fromString "2024-01-15T12:00:00-05:00[America/New_York]"
inTokyo <- ZonedDateTime.withTimeZone "Asia/Tokyo" zoned
Console.log (ZonedDateTime.toString inTokyo)
2024-01-16T02:00:00+09:00[Asia/Tokyo]
#withCalendar Source
withCalendar :: String -> ZonedDateTime -> Effect ZonedDateTimeReturns a copy with the same instant and time zone, but a different calendar.
exampleWithCalendar :: Effect Unit
exampleWithCalendar = do
zoned <- ZonedDateTime.fromString "2024-01-15T12:00:00-05:00[America/New_York]"
gregory <- ZonedDateTime.withCalendar "gregory" zoned
Console.log (ZonedDateTime.toStringWithOptions { calendarName: CalendarName.Always } gregory)
2024-01-15T12:00:00-05:00[America/New_York][u-ca=gregory]
#withPlainTime Source
withPlainTime :: PlainTime -> ZonedDateTime -> Effect ZonedDateTimeReturns a copy with the wall-clock time replaced.
exampleWithPlainTime :: Effect Unit
exampleWithPlainTime = do
zoned <- ZonedDateTime.fromString "2024-01-15T09:30:45-05:00[America/New_York]"
closingTime <- PlainTime.fromString "17:00:00"
updated <- ZonedDateTime.withPlainTime closingTime zoned
Console.log (ZonedDateTime.toString updated)
2024-01-15T17:00:00-05:00[America/New_York]
#withPlainDate Source
withPlainDate :: PlainDate -> ZonedDateTime -> Effect ZonedDateTimeReturns a copy with the calendar date replaced.
exampleWithPlainDate :: Effect Unit
exampleWithPlainDate = do
zoned <- ZonedDateTime.fromString "2024-01-15T09:30:45-05:00[America/New_York]"
nextDay <- PlainDate.fromString "2024-01-16"
updated <- ZonedDateTime.withPlainDate nextDay zoned
Console.log (ZonedDateTime.toString updated)
2024-01-16T09:30:45-05:00[America/New_York]
#untilWithOptions Source
untilWithOptions :: forall provided. ConvertOptionsWithDefaults ToDifferenceOptions (Record DifferenceOptions) (Record provided) (Record DifferenceOptions) => Record provided -> ZonedDateTime -> ZonedDateTime -> Effect DurationDuration from subject (last arg) until other (second arg). Arg order: untilWithOptions options other subject.
exampleUntilWithOptions :: Effect Unit
exampleUntilWithOptions = do
locale <- JS.Intl.Locale.new_ "en-US"
departure <- ZonedDateTime.fromString "2020-03-08T11:55:00+08:00[Asia/Hong_Kong]"
arrival <- ZonedDateTime.fromString "2020-03-08T09:50:00-07:00[America/Los_Angeles]"
flightTime <- ZonedDateTime.untilWithOptions { largestUnit: TemporalUnit.Hour } arrival departure
formatter <- JS.Intl.DurationFormat.new [ locale ] { style: "long" }
Console.log ("Flight time: " <> JS.Intl.DurationFormat.format formatter flightTime)
Flight time: 12 hours, 55 minutes
#until Source
until :: ZonedDateTime -> ZonedDateTime -> Effect DurationSame as untilWithOptions with default options. Arg order: until other subject.
exampleUntil :: Effect Unit
exampleUntil = do
start <- ZonedDateTime.fromString "2024-01-01T00:00:00[America/New_York]"
end <- ZonedDateTime.fromString "2024-01-02T00:00:00[America/New_York]"
duration <- ZonedDateTime.until end start
Console.log (Duration.toString duration)
PT24H
#sinceWithOptions Source
sinceWithOptions :: forall provided. ConvertOptionsWithDefaults ToDifferenceOptions (Record DifferenceOptions) (Record provided) (Record DifferenceOptions) => Record provided -> ZonedDateTime -> ZonedDateTime -> Effect DurationDuration from other to subject (inverse of untilWithOptions). Arg order: sinceWithOptions options other subject.
exampleSinceWithOptions :: Effect Unit
exampleSinceWithOptions = do
locale <- JS.Intl.Locale.new_ "en-US"
start <- ZonedDateTime.fromString "2024-01-01T00:00:00[America/New_York]"
end <- ZonedDateTime.fromString "2024-03-15T12:00:00[America/New_York]"
elapsed <- ZonedDateTime.sinceWithOptions { largestUnit: TemporalUnit.Hour } start end
formatter <- JS.Intl.DurationFormat.new [ locale ] { style: "long" }
Console.log ("Elapsed: " <> JS.Intl.DurationFormat.format formatter elapsed)
Elapsed: 1,787 hours
#since Source
since :: ZonedDateTime -> ZonedDateTime -> Effect DurationSame as sinceWithOptions with default options. Arg order: since other subject.
exampleSince :: Effect Unit
exampleSince = do
start <- ZonedDateTime.fromString "2024-01-01T00:00:00[America/New_York]"
end <- ZonedDateTime.fromString "2024-03-15T12:00:00[America/New_York]"
elapsed <- ZonedDateTime.since start end
Console.log (Duration.toString elapsed)
PT1787H
#round Source
round :: forall provided. ConvertOptionsWithDefaults ToRoundOptions (Record RoundOptions) (Record provided) (Record RoundOptions) => Record provided -> ZonedDateTime -> Effect ZonedDateTimeRounds this zoned date-time to a smaller unit. Options: smallestUnit, roundingIncrement, roundingMode.
exampleRound :: Effect Unit
exampleRound = do
zoned <- ZonedDateTime.fromString "2024-01-15T09:30:45.123456789-05:00[America/New_York]"
rounded <- ZonedDateTime.round { smallestUnit: TemporalUnit.Minute, roundingMode: RoundingMode.HalfExpand } zoned
Console.log (ZonedDateTime.toString rounded)
2024-01-15T09:31:00-05:00[America/New_York]
#startOfDay Source
startOfDay :: ZonedDateTime -> Effect ZonedDateTimeReturns the start of the calendar day in this time zone.
exampleStartOfDay :: Effect Unit
exampleStartOfDay = do
zoned <- ZonedDateTime.fromString "2024-03-10T12:00:00-04:00[America/New_York]"
start <- ZonedDateTime.startOfDay zoned
Console.log (ZonedDateTime.toString start)
2024-03-10T00:00:00-05:00[America/New_York]
#getTimeZoneTransition Source
getTimeZoneTransition :: String -> ZonedDateTime -> Maybe ZonedDateTimeGets the next or previous time zone transition. Direction: "next" or "previous".
exampleGetTimeZoneTransition :: Effect Unit
exampleGetTimeZoneTransition = do
zoned <- ZonedDateTime.fromString "2024-03-09T12:00:00-05:00[America/New_York]"
case ZonedDateTime.getTimeZoneTransition "next" zoned of
Nothing -> Console.log "No transition"
Just transition -> Console.log (ZonedDateTime.toString transition)
2024-03-10T03:00:00-04:00[America/New_York]
#toInstant Source
toInstant :: ZonedDateTime -> InstantExtracts the absolute instant (no time zone).
exampleToInstant :: Effect Unit
exampleToInstant = do
zoned <- ZonedDateTime.fromString "2024-01-15T12:00:00-05:00[America/New_York]"
Console.log (Instant.toString (ZonedDateTime.toInstant zoned))
2024-01-15T17:00:00Z
#toPlainDateTime Source
toPlainDateTime :: ZonedDateTime -> PlainDateTimeExtracts date and time in the zoned wall-clock view (drops time zone).
exampleToPlainDateTime :: Effect Unit
exampleToPlainDateTime = do
zoned <- ZonedDateTime.fromString "2024-01-15T12:00:00-05:00[America/New_York]"
Console.log (PlainDateTime.toString (ZonedDateTime.toPlainDateTime zoned))
2024-01-15T12:00:00
#toPlainDate Source
toPlainDate :: ZonedDateTime -> PlainDateExtracts the calendar date in the zoned wall-clock view.
exampleToPlainDate :: Effect Unit
exampleToPlainDate = do
zoned <- ZonedDateTime.fromString "2024-01-15T12:00:00-05:00[America/New_York]"
Console.log (PlainDate.toString (ZonedDateTime.toPlainDate zoned))
2024-01-15
#toPlainTime Source
toPlainTime :: ZonedDateTime -> PlainTimeExtracts the wall-clock time in the associated time zone.
exampleToPlainTime :: Effect Unit
exampleToPlainTime = do
zoned <- ZonedDateTime.fromString "2024-01-15T12:00:00-05:00[America/New_York]"
Console.log (PlainTime.toString (ZonedDateTime.toPlainTime zoned))
12:00:00
#toPlainYearMonth Source
toPlainYearMonth :: ZonedDateTime -> PlainYearMonthExtracts the year and month in the zoned wall-clock view.
exampleToPlainYearMonth :: Effect Unit
exampleToPlainYearMonth = do
zoned <- ZonedDateTime.fromString "2024-01-15T12:00:00-05:00[America/New_York]"
Console.log (PlainYearMonth.toString (ZonedDateTime.toPlainYearMonth zoned))
2024-01
#toPlainMonthDay Source
toPlainMonthDay :: ZonedDateTime -> PlainMonthDayExtracts the month and day in the zoned wall-clock view.
exampleToPlainMonthDay :: Effect Unit
exampleToPlainMonthDay = do
zoned <- ZonedDateTime.fromString "2024-01-15T12:00:00-05:00[America/New_York]"
Console.log (PlainMonthDay.toString (ZonedDateTime.toPlainMonthDay zoned))
01-15
#toStringWithOptions Source
toStringWithOptions :: forall provided. ConvertOptionsWithDefaults ToToStringOptions (Record ToStringOptions) (Record provided) (Record ToStringOptions) => Record provided -> ZonedDateTime -> StringSerializes to ISO 8601 format with time zone. Options: calendarName, timeZoneName, offset, fractionalSecondDigits, smallestUnit, roundingMode.
exampleToStringWithOptions :: Effect Unit
exampleToStringWithOptions = do
zoned <- ZonedDateTime.fromString "2024-01-15T12:00:00.123456789-05:00[America/New_York]"
Console.log
( ZonedDateTime.toStringWithOptions
{ smallestUnit: TemporalUnit.Minute
, calendarName: CalendarName.Never
}
zoned
)
2024-01-15T12:00-05:00[America/New_York]
#toString Source
toString :: ZonedDateTime -> StringSame as toStringWithOptions with default options.
exampleToString :: Effect Unit
exampleToString = do
zoned <- ZonedDateTime.fromString "2024-01-15T12:00:00-05:00[America/New_York]"
Console.log (ZonedDateTime.toString zoned)
2024-01-15T12:00:00-05:00[America/New_York]
#ToFromOptions Source
data ToFromOptionsInstances
ConvertOption ToFromOptions "overflow" Overflow StringConvertOption ToFromOptions "overflow" String StringConvertOption ToFromOptions "disambiguation" Disambiguation StringConvertOption ToFromOptions "disambiguation" String StringConvertOption ToFromOptions "offset" OffsetDisambiguation StringConvertOption ToFromOptions "offset" String String
#ToArithmeticOptions Source
data ToArithmeticOptionsInstances
ConvertOption ToArithmeticOptions "overflow" Overflow StringConvertOption ToArithmeticOptions "overflow" String StringConvertOption ToArithmeticOptions "disambiguation" Disambiguation StringConvertOption ToArithmeticOptions "disambiguation" String String
#ToDifferenceOptions Source
data ToDifferenceOptionsInstances
ConvertOption ToDifferenceOptions "largestUnit" TemporalUnit StringConvertOption ToDifferenceOptions "largestUnit" String StringConvertOption ToDifferenceOptions "smallestUnit" TemporalUnit StringConvertOption ToDifferenceOptions "smallestUnit" String StringConvertOption ToDifferenceOptions "roundingIncrement" Int IntConvertOption ToDifferenceOptions "roundingMode" RoundingMode StringConvertOption ToDifferenceOptions "roundingMode" String String
#ToRoundOptions Source
data ToRoundOptionsInstances
ConvertOption ToRoundOptions "smallestUnit" TemporalUnit StringConvertOption ToRoundOptions "smallestUnit" String StringConvertOption ToRoundOptions "roundingIncrement" Int IntConvertOption ToRoundOptions "roundingMode" RoundingMode StringConvertOption ToRoundOptions "roundingMode" String String
#ToToStringOptions Source
data ToToStringOptionsInstances
ConvertOption ToToStringOptions "calendarName" CalendarName StringConvertOption ToToStringOptions "calendarName" String StringConvertOption ToToStringOptions "timeZoneName" String StringConvertOption ToToStringOptions "offset" String StringConvertOption ToToStringOptions "fractionalSecondDigits" Int ForeignConvertOption ToToStringOptions "fractionalSecondDigits" String ForeignConvertOption ToToStringOptions "smallestUnit" TemporalUnit StringConvertOption ToToStringOptions "smallestUnit" String StringConvertOption ToToStringOptions "roundingMode" RoundingMode StringConvertOption ToToStringOptions "roundingMode" String String
Re-exports from JS.Temporal.ZonedDateTime.Internal
- Modules
- JS.
Temporal. Duration - JS.
Temporal. Duration. Internal - JS.
Temporal. Instant - JS.
Temporal. Instant. Internal - JS.
Temporal. Internal - JS.
Temporal. Now - JS.
Temporal. Options. CalendarName - JS.
Temporal. Options. Disambiguation - JS.
Temporal. Options. OffsetDisambiguation - JS.
Temporal. Options. Overflow - JS.
Temporal. Options. RoundingMode - JS.
Temporal. Options. TemporalUnit - JS.
Temporal. PlainDate - JS.
Temporal. PlainDate. Internal - JS.
Temporal. PlainDateTime - JS.
Temporal. PlainDateTime. Internal - JS.
Temporal. PlainMonthDay - JS.
Temporal. PlainMonthDay. Internal - JS.
Temporal. PlainTime - JS.
Temporal. PlainTime. Internal - JS.
Temporal. PlainYearMonth - JS.
Temporal. PlainYearMonth. Internal - JS.
Temporal. ZonedDateTime - JS.
Temporal. ZonedDateTime. Internal