JS.Temporal.PlainDateTime
- Package
- purescript-js-temporal
- Repository
- pete-murphy/purescript-js-temporal
A date and time (year, month, day, hour, minute, etc.) without time zone. Use for wall-clock times that are not tied to a specific instant (e.g. "Jan 15, 2024 at 3pm"). Combine with a time zone to get a ZonedDateTime.
#new Source
new :: forall provided rest. Union provided rest PlainDateTimeComponents => Record provided -> Effect PlainDateTimeCreates a PlainDateTime from component fields.
locale <- JS.Intl.Locale.new_ "en-US"
dateTime <- PlainDateTime.new
{ year: 2024
, month: 1
, day: 15
, hour: 9
, minute: 30
, second: 0
}
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long", timeStyle: "medium" }
Console.log (JS.Intl.DateTimeFormat.format formatter dateTime)
January 15, 2024 at 9:30:00 AM
#from Source
from :: forall provided. ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record provided) (Record OverflowOptions) => Record provided -> String -> Effect PlainDateTimeParses a date-time string (e.g. "2024-01-15T15:30:00"). Options: overflow.
locale <- JS.Intl.Locale.new_ "en-US"
dateTime <- PlainDateTime.from { overflow: Overflow.Constrain } "2024-01-15T09:30:00"
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long", timeStyle: "medium" }
Console.log (JS.Intl.DateTimeFormat.format formatter dateTime)
January 15, 2024 at 9:30:00 AM
#year Source
year :: PlainDateTime -> IntISO calendar year number.
#month Source
month :: PlainDateTime -> IntMonth number within the year.
#day Source
day :: PlainDateTime -> IntDay of the month.
#monthCode Source
monthCode :: PlainDateTime -> StringCalendar-specific month code, such as M01.
#dayOfWeek Source
dayOfWeek :: PlainDateTime -> IntDay of the week, from 1 (Monday) to 7 (Sunday).
#dayOfYear Source
dayOfYear :: PlainDateTime -> IntDay number within the year.
#weekOfYear Source
weekOfYear :: PlainDateTime -> Maybe IntWeek number within the year when defined by the calendar.
#yearOfWeek Source
yearOfWeek :: PlainDateTime -> Maybe IntWeek-numbering year when defined by the calendar.
#daysInMonth Source
daysInMonth :: PlainDateTime -> IntNumber of days in the month.
#daysInYear Source
daysInYear :: PlainDateTime -> IntNumber of days in the year.
#daysInWeek Source
daysInWeek :: PlainDateTime -> IntNumber of days in the week for this calendar.
#monthsInYear Source
monthsInYear :: PlainDateTime -> IntNumber of months in the year for this calendar.
#inLeapYear Source
inLeapYear :: PlainDateTime -> BooleanWhether the year is a leap year in this calendar.
#calendarId Source
calendarId :: PlainDateTime -> StringCalendar identifier, such as "iso8601".
#eraYear Source
eraYear :: PlainDateTime -> Maybe IntYear number within the current era when available.
#hour Source
hour :: PlainDateTime -> IntHour component.
#minute Source
minute :: PlainDateTime -> IntMinute component.
#second Source
second :: PlainDateTime -> IntSecond component.
#millisecond Source
millisecond :: PlainDateTime -> IntMillisecond component.
#microsecond Source
microsecond :: PlainDateTime -> IntMicrosecond component.
#nanosecond Source
nanosecond :: PlainDateTime -> IntNanosecond component.
#add Source
add :: forall provided. ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record provided) (Record OverflowOptions) => Record provided -> Duration -> PlainDateTime -> Effect PlainDateTimeAdds a duration. Arg order: add options duration subject. Options: overflow.
locale <- JS.Intl.Locale.new_ "en-US"
start <- PlainDateTime.from_ "2024-01-15T09:00:00"
twoHours <- Duration.new { hours: 2 }
end <- PlainDateTime.add { overflow: Overflow.Constrain } twoHours start
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long", timeStyle: "medium" }
Console.log (JS.Intl.DateTimeFormat.format formatter end)
January 15, 2024 at 11:00:00 AM
#add_ Source
add_ :: Duration -> PlainDateTime -> Effect PlainDateTimeSame as add with default options.
#subtract Source
subtract :: forall provided. ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record provided) (Record OverflowOptions) => Record provided -> Duration -> PlainDateTime -> Effect PlainDateTimeSubtracts a duration. Arg order: subtract options duration subject (subject minus duration).
Options: overflow.
locale <- JS.Intl.Locale.new_ "en-US"
start <- PlainDateTime.from_ "2024-01-15T11:00:00"
twoHours <- Duration.new { hours: 2 }
earlier <- PlainDateTime.subtract { overflow: Overflow.Constrain } twoHours start
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long", timeStyle: "medium" }
Console.log (JS.Intl.DateTimeFormat.format formatter earlier)
January 15, 2024 at 9:00:00 AM
#subtract_ Source
subtract_ :: Duration -> PlainDateTime -> Effect PlainDateTimeSame as subtract with default options.
#with Source
with :: forall optsProvided fields rest. Union fields rest WithFields => ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record optsProvided) (Record OverflowOptions) => Record optsProvided -> Record fields -> PlainDateTime -> Effect PlainDateTimeReturns a new PlainDateTime with specified fields replaced. Options: overflow.
locale <- JS.Intl.Locale.new_ "en-US"
dateTime <- PlainDateTime.from_ "2024-01-15T09:30:45"
noon <- PlainDateTime.with { overflow: Overflow.Constrain } { hour: 12, minute: 0, second: 0 } dateTime
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long", timeStyle: "medium" }
Console.log (JS.Intl.DateTimeFormat.format formatter noon)
January 15, 2024 at 12:00:00 PM
#with_ Source
with_ :: forall fields rest. Union fields rest WithFields => Record fields -> PlainDateTime -> Effect PlainDateTimeSame as with with default options.
#withPlainTime Source
withPlainTime :: PlainTime -> PlainDateTime -> Effect PlainDateTimeReturns a new PlainDateTime with the time component replaced.
locale <- JS.Intl.Locale.new_ "en-US"
dateTime <- PlainDateTime.from_ "2024-01-15T09:30:00"
closingTime <- PlainTime.from_ "17:00:00"
updated <- PlainDateTime.withPlainTime closingTime dateTime
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long", timeStyle: "medium" }
Console.log (JS.Intl.DateTimeFormat.format formatter updated)
January 15, 2024 at 5:00:00 PM
#withCalendar Source
withCalendar :: String -> PlainDateTime -> Effect PlainDateTimeReturns a new PlainDateTime that uses a different calendar.
dateTime <- PlainDateTime.from_ "2019-05-01T09:30:00"
japanese <- PlainDateTime.withCalendar "japanese" dateTime
Console.log (PlainDateTime.calendarId japanese)
japanese
#until Source
until :: forall provided. ConvertOptionsWithDefaults ToDifferenceOptions (Record DifferenceOptions) (Record provided) (Record DifferenceOptions) => Record provided -> PlainDateTime -> PlainDateTime -> Effect DurationComputes the duration from subject (last arg) until other (second arg).
Positive when other is later. Arg order: until options other subject.
Options: largestUnit, smallestUnit, roundingIncrement, roundingMode.
locale <- JS.Intl.Locale.new_ "en-US"
now <- Now.plainDateTimeISO_
>>= PlainDateTime.round { smallestUnit: TemporalUnit.Second }
nextBilling <- do
aprilFirst <- PlainDateTime.new
{ year: PlainDateTime.year now
, month: 4
, day: 1
}
if aprilFirst < now then do
oneYear <- Duration.new { years: 1 }
PlainDateTime.add_ oneYear aprilFirst
else
pure aprilFirst
duration <- PlainDateTime.until
{ smallestUnit: TemporalUnit.Day }
nextBilling
now
durationFormatter <- JS.Intl.DurationFormat.new [ locale ] { style: JS.Intl.Options.DurationFormatStyle.Long }
Console.log (JS.Intl.DurationFormat.format durationFormatter duration <> " until next billing")
23 days until next billing
#until_ Source
until_ :: PlainDateTime -> PlainDateTime -> Effect DurationSame as until with default options.
#since Source
since :: forall provided. ConvertOptionsWithDefaults ToDifferenceOptions (Record DifferenceOptions) (Record provided) (Record DifferenceOptions) => Record provided -> PlainDateTime -> PlainDateTime -> Effect DurationDuration from other to subject (inverse of until). Arg order: since options other subject.
locale <- JS.Intl.Locale.new_ "en-US"
start <- PlainDateTime.from_ "2024-01-01T00:00:00"
end <- PlainDateTime.from_ "2024-03-15T12:00:00"
elapsed <- PlainDateTime.since { largestUnit: TemporalUnit.Day } start end
formatter <- JS.Intl.DurationFormat.new [ locale ] { style: JS.Intl.Options.DurationFormatStyle.Long }
Console.log ("Elapsed: " <> JS.Intl.DurationFormat.format formatter elapsed)
Elapsed: 74 days, 12 hours
#since_ Source
since_ :: PlainDateTime -> PlainDateTime -> Effect DurationSame as since with default options.
#round Source
round :: forall provided. ConvertOptionsWithDefaults ToRoundOptions (Record RoundOptions) (Record provided) (Record RoundOptions) => Record provided -> PlainDateTime -> Effect PlainDateTimeRounds to a specified unit. Options: smallestUnit, roundingIncrement, roundingMode.
locale <- JS.Intl.Locale.new_ "en-US"
dateTime <- PlainDateTime.from_ "2024-01-15T09:30:45.123"
rounded <- PlainDateTime.round { smallestUnit: TemporalUnit.Minute } dateTime
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long", timeStyle: "medium" }
Console.log (JS.Intl.DateTimeFormat.format formatter rounded)
January 15, 2024 at 9:31:00 AM
#toString Source
toString :: forall provided. ConvertOptionsWithDefaults ToToStringOptions (Record ToStringOptions) (Record provided) (Record ToStringOptions) => Record provided -> PlainDateTime -> StringSerializes to ISO 8601 format. Options: fractionalSecondDigits, smallestUnit, roundingMode, calendarName.
dateTime <- PlainDateTime.from_ "2024-01-15T09:30:00"
Console.log (PlainDateTime.toString { smallestUnit: TemporalUnit.Minute } dateTime)
2024-01-15T09:30
#toString_ Source
toString_ :: PlainDateTime -> StringDefault ISO 8601 serialization (no options). Prefer over toString {}.
dateTime <- PlainDateTime.from_ "2024-01-15T09:30:00"
Console.log (PlainDateTime.toString_ dateTime)
2024-01-15T09:30:00
#fromDateTime Source
fromDateTime :: DateTime -> Effect PlainDateTimeConverts a purescript-datetime DateTime to a PlainDateTime.
#toDateTime Source
toDateTime :: PlainDateTime -> DateTimeConverts a PlainDateTime to a purescript-datetime DateTime.
#toPlainDate Source
toPlainDate :: PlainDateTime -> PlainDateExtracts the date component.
locale <- JS.Intl.Locale.new_ "en-US"
dateTime <- PlainDateTime.from_ "2024-01-15T09:30:00"
date <- pure (PlainDateTime.toPlainDate dateTime)
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter date)
January 15, 2024
#toPlainTime Source
toPlainTime :: PlainDateTime -> PlainTimeExtracts the time component.
locale <- JS.Intl.Locale.new_ "en-US"
dateTime <- PlainDateTime.from_ "2024-01-15T09:30:00"
time <- pure (PlainDateTime.toPlainTime dateTime)
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { timeStyle: "medium" }
Console.log (JS.Intl.DateTimeFormat.format formatter time)
9:30:00 AM
#toZonedDateTime Source
toZonedDateTime :: String -> PlainDateTime -> Effect ZonedDateTimeInterprets this date-time as occurring in the given time zone.
locale <- JS.Intl.Locale.new_ "en-US"
plain <- PlainDateTime.from_ "2024-01-15T09:30:00"
zoned <- PlainDateTime.toZonedDateTime "America/New_York" plain
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long", timeStyle: "medium" }
Console.log (JS.Intl.DateTimeFormat.format formatter zoned)
January 15, 2024 at 9:30:00 AM
#ToOverflowOptions Source
data ToOverflowOptionsInstances
ConvertOption ToOverflowOptions "overflow" Overflow StringConvertOption ToOverflowOptions "overflow" 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 "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.PlainDateTime.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