JS.Temporal.PlainDate
- Package
- purescript-js-temporal
- Repository
- pete-murphy/purescript-js-temporal
A calendar date (year, month, day) without time or time zone. Use for date-only values (e.g. birthdays, all-day events). Uses ISO 8601 calendar by default.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainDate
#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
#ToOverflowOptions Source
data ToOverflowOptionsInstances
ConvertOption ToOverflowOptions "overflow" Overflow StringConvertOption ToOverflowOptions "overflow" String String
#ToToStringOptions Source
data ToToStringOptionsInstances
ConvertOption ToToStringOptions "calendarName" CalendarName StringConvertOption ToToStringOptions "calendarName" String String
#addWithOptions Source
addWithOptions :: forall provided. ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record provided) (Record OverflowOptions) => Record provided -> Duration -> PlainDate -> Effect PlainDateAdds a duration to a date. Supports calendar durations. Options: overflow.
exampleAddWithOptions :: Effect Unit
exampleAddWithOptions = do
locale <- JS.Intl.Locale.new_ "en-US"
date <- PlainDate.fromString "2024-03-15"
oneWeek <- Duration.from { weeks: 1 }
later <- PlainDate.addWithOptions { overflow: Overflow.Constrain } oneWeek date
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter later)
March 22, 2024
#add Source
add :: Duration -> PlainDate -> Effect PlainDateSame as addWithOptions with default options.
exampleAdd :: Effect Unit
exampleAdd = do
locale <- JS.Intl.Locale.new_ "en-US"
date <- PlainDate.fromString "2024-03-15"
oneWeek <- Duration.from { weeks: 1 }
later <- PlainDate.add oneWeek date
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter later)
March 22, 2024
#calendarId Source
calendarId :: PlainDate -> StringIdentifier of the associated calendar (for example "iso8601").
exampleCalendarId :: Effect Unit
exampleCalendarId = do
date <- PlainDate.fromString "2024-07-01"
Console.log ("Calendar: " <> PlainDate.calendarId date)
Calendar: iso8601
#daysInMonth Source
daysInMonth :: PlainDate -> IntNumber of days in the current month.
exampleDaysInMonth :: Effect Unit
exampleDaysInMonth = do
date <- PlainDate.fromString "2024-02-01"
Console.log ("Days in Feb 2024: " <> show (PlainDate.daysInMonth date))
Days in Feb 2024: 29
#daysInWeek Source
daysInWeek :: PlainDate -> IntNumber of days in the current week according to the calendar.
exampleDaysInWeek :: Effect Unit
exampleDaysInWeek = do
date <- PlainDate.fromString "2024-07-01"
Console.log ("Days in week: " <> show (PlainDate.daysInWeek date))
Days in week: 7
#daysInYear Source
daysInYear :: PlainDate -> IntNumber of days in the current year.
exampleDaysInYear :: Effect Unit
exampleDaysInYear = do
date <- PlainDate.fromString "2024-07-01"
Console.log ("Days in 2024: " <> show (PlainDate.daysInYear date))
Days in 2024: 366
#fromWithOptions Source
fromWithOptions :: forall optsProvided provided rest. Union provided rest PlainDateComponents => ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record optsProvided) (Record OverflowOptions) => Record optsProvided -> Record provided -> Effect PlainDateCreates a PlainDate from component fields. Options: overflow.
exampleFromWithOptions :: Effect Unit
exampleFromWithOptions = do
locale <- JS.Intl.Locale.new_ "en-US"
date <- PlainDate.fromWithOptions { overflow: Overflow.Constrain } { year: 2024, month: 7, day: 1 }
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter date)
July 1, 2024
#fromStringWithOptions Source
fromStringWithOptions :: forall provided. ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record provided) (Record OverflowOptions) => Record provided -> String -> Effect PlainDateCreates a PlainDate from an RFC 9557 / ISO 8601 date string (e.g. "2024-01-15").
Options: overflow.
exampleFromStringWithOptions :: Effect Unit
exampleFromStringWithOptions = do
date <- PlainDate.fromStringWithOptions { overflow: Overflow.Constrain } "2024-01-15"
Console.log (PlainDate.toString date)
2024-01-15
#fromString Source
fromString :: String -> Effect PlainDateSame as fromStringWithOptions with default options.
exampleFromString :: Effect Unit
exampleFromString = do
locale <- JS.Intl.Locale.new_ "en-US"
date <- PlainDate.fromString "2024-01-15"
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter date)
January 15, 2024
#from Source
from :: forall provided rest. Union provided rest PlainDateComponents => Record provided -> Effect PlainDateSame as fromWithOptions with default options.
exampleFrom :: Effect Unit
exampleFrom = do
locale <- JS.Intl.Locale.new_ "en-US"
date <- PlainDate.from { year: 2024, month: 7, day: 1 }
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter date)
July 1, 2024
#inLeapYear Source
inLeapYear :: PlainDate -> BooleanWhether the current year is a leap year in this calendar.
exampleInLeapYear :: Effect Unit
exampleInLeapYear = do
date <- PlainDate.fromString "2024-07-01"
Console.log ("2024 is leap year: " <> show (PlainDate.inLeapYear date))
2024 is leap year: true
#monthsInYear Source
monthsInYear :: PlainDate -> IntNumber of months in the current year.
exampleMonthsInYear :: Effect Unit
exampleMonthsInYear = do
date <- PlainDate.fromString "2024-07-01"
Console.log ("Months in year: " <> show (PlainDate.monthsInYear date))
Months in year: 12
#sinceWithOptions Source
sinceWithOptions :: forall provided. ConvertOptionsWithDefaults ToDifferenceOptions (Record DifferenceOptions) (Record provided) (Record DifferenceOptions) => Record provided -> PlainDate -> PlainDate -> Effect DurationDuration from other to subject (inverse of untilWithOptions). Arg order: since options other subject.
exampleSinceWithOptions :: Effect Unit
exampleSinceWithOptions = do
locale <- JS.Intl.Locale.new_ "en-US"
start <- PlainDate.fromString "2024-01-01"
end <- PlainDate.fromString "2024-03-15"
elapsed <- PlainDate.sinceWithOptions { largestUnit: TemporalUnit.Day } start end
formatter <- JS.Intl.DurationFormat.new [ locale ] { style: "long" }
Console.log ("Elapsed: " <> JS.Intl.DurationFormat.format formatter elapsed)
Elapsed: 74 days
#since Source
since :: PlainDate -> PlainDate -> Effect DurationSame as sinceWithOptions with default options.
exampleSince :: Effect Unit
exampleSince = do
start <- PlainDate.fromString "2024-01-01"
end <- PlainDate.fromString "2024-03-15"
elapsed <- PlainDate.since start end
Console.log (Duration.toString elapsed)
P74D
#subtractWithOptions Source
subtractWithOptions :: forall provided. ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record provided) (Record OverflowOptions) => Record provided -> Duration -> PlainDate -> Effect PlainDateSubtracts a duration. Arg order: subtractWithOptions options duration subject. Options: overflow.
exampleSubtractWithOptions :: Effect Unit
exampleSubtractWithOptions = do
locale <- JS.Intl.Locale.new_ "en-US"
date <- PlainDate.fromString "2024-03-15"
oneWeek <- Duration.from { weeks: 1 }
earlier <- PlainDate.subtractWithOptions { overflow: Overflow.Constrain } oneWeek date
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter earlier)
March 8, 2024
#subtract Source
subtract :: Duration -> PlainDate -> Effect PlainDateSame as subtractWithOptions with default options.
exampleSubtract :: Effect Unit
exampleSubtract = do
locale <- JS.Intl.Locale.new_ "en-US"
date <- PlainDate.fromString "2024-03-15"
oneWeek <- Duration.from { weeks: 1 }
earlier <- PlainDate.subtract oneWeek date
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter earlier)
March 8, 2024
#toPlainDateTime Source
toPlainDateTime :: PlainTime -> PlainDate -> PlainDateTimeCombines a PlainTime with this date to form a PlainDateTime.
exampleToPlainDateTime :: Effect Unit
exampleToPlainDateTime = do
date <- PlainDate.fromString "2024-01-15"
time <- PlainTime.fromString "09:30:00"
Console.log (PlainDateTime.toString (PlainDate.toPlainDateTime time date))
2024-01-15T09:30:00
#toPlainMonthDay Source
toPlainMonthDay :: PlainDate -> PlainMonthDayExtracts the month and day.
exampleToPlainMonthDay :: Effect Unit
exampleToPlainMonthDay = do
date <- PlainDate.fromString "2024-01-15"
Console.log (PlainMonthDay.toString (PlainDate.toPlainMonthDay date))
01-15
#toZonedDateTimeWithPlainTime Source
toZonedDateTimeWithPlainTime :: String -> PlainTime -> PlainDate -> Effect ZonedDateTimeConverts to a ZonedDateTime at the given time in the given time zone.
exampleToZonedDateTimeWithPlainTime :: Effect Unit
exampleToZonedDateTimeWithPlainTime = do
date <- PlainDate.fromString "2024-01-15"
time <- PlainTime.fromString "09:30:00"
zoned <- PlainDate.toZonedDateTimeWithPlainTime "America/New_York" time date
Console.log (ZonedDateTime.toString zoned)
2024-01-15T09:30:00-05:00[America/New_York]
#toZonedDateTime Source
toZonedDateTime :: String -> PlainDate -> Effect ZonedDateTimeConverts to a ZonedDateTime at midnight in the given time zone.
exampleToZonedDateTime :: Effect Unit
exampleToZonedDateTime = do
date <- PlainDate.fromString "2024-01-15"
zoned <- PlainDate.toZonedDateTime "America/New_York" date
Console.log (ZonedDateTime.toString zoned)
2024-01-15T00:00:00-05:00[America/New_York]
#toPlainYearMonth Source
toPlainYearMonth :: PlainDate -> PlainYearMonthExtracts the year and month.
exampleToPlainYearMonth :: Effect Unit
exampleToPlainYearMonth = do
date <- PlainDate.fromString "2024-01-15"
Console.log (PlainYearMonth.toString (PlainDate.toPlainYearMonth date))
2024-01
#toStringWithOptions Source
toStringWithOptions :: forall provided. ConvertOptionsWithDefaults ToToStringOptions (Record ToStringOptions) (Record provided) (Record ToStringOptions) => Record provided -> PlainDate -> StringSerializes to ISO 8601 date format. Options: calendarName.
exampleToStringWithOptions :: Effect Unit
exampleToStringWithOptions = do
date <- PlainDate.fromString "2024-01-15"
Console.log (PlainDate.toStringWithOptions { calendarName: CalendarName.Always } date)
2024-01-15[u-ca=iso8601]
#toString Source
toString :: PlainDate -> StringSame as toStringWithOptions with default options.
exampleToString :: Effect Unit
exampleToString = do
date <- PlainDate.fromString "2024-01-15"
Console.log (PlainDate.toString date)
2024-01-15
#untilWithOptions Source
untilWithOptions :: forall provided. ConvertOptionsWithDefaults ToDifferenceOptions (Record DifferenceOptions) (Record provided) (Record DifferenceOptions) => Record provided -> PlainDate -> PlainDate -> Effect DurationDuration from subject (last arg) until other (second arg). Arg order: until options other subject.
Options: largestUnit, smallestUnit, roundingIncrement, roundingMode.
exampleUntilWithOptions :: Effect Unit
exampleUntilWithOptions = do
locale <- JS.Intl.Locale.new_ "en-US"
today <- Now.plainDateISO
futureDate <- PlainDate.fromString "2026-12-25"
untilDuration <- PlainDate.untilWithOptions { smallestUnit: TemporalUnit.Day } futureDate today
formatter <- JS.Intl.DurationFormat.new [ locale ] { style: "long" }
Console.log (JS.Intl.DurationFormat.format formatter untilDuration <> " until Christmas 2026")
228 days until Christmas 2026
#until Source
until :: PlainDate -> PlainDate -> Effect DurationSame as untilWithOptions with default options.
exampleUntil :: Effect Unit
exampleUntil = do
start <- PlainDate.fromString "2024-01-01"
end <- PlainDate.fromString "2024-03-15"
duration <- PlainDate.until end start
Console.log (Duration.toString duration)
P74D
#weekOfYear Source
weekOfYear :: PlainDate -> Maybe IntWeek number within the year, if the calendar defines week numbering.
exampleWeekOfYear :: Effect Unit
exampleWeekOfYear = do
date <- PlainDate.fromString "2024-07-01"
Console.log ("Week of year: " <> show (PlainDate.weekOfYear date))
Week of year: (Just 27)
#withWithOptions Source
withWithOptions :: forall optsProvided fields rest. Union fields rest WithFields => ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record optsProvided) (Record OverflowOptions) => Record optsProvided -> Record fields -> PlainDate -> Effect PlainDateReturns a new PlainDate with specified fields replaced. Because PlainDate is immutable, this is the way to "set" fields. Options: overflow.
exampleWithWithOptions :: Effect Unit
exampleWithWithOptions = do
date <- PlainDate.fromString "2021-07-06"
lastDay <- PlainDate.withWithOptions { overflow: Overflow.Constrain } { day: PlainDate.daysInMonth date } date
Console.log (PlainDate.toString lastDay)
2021-07-31
#withCalendar Source
withCalendar :: String -> PlainDate -> Effect PlainDateReturns a new PlainDate with the given calendar (for example "iso8601").
exampleWithCalendar :: Effect Unit
exampleWithCalendar = do
date <- PlainDate.fromString "2024-01-15"
gregory <- PlainDate.withCalendar "gregory" date
Console.log (PlainDate.toStringWithOptions { calendarName: CalendarName.Always } gregory)
2024-01-15[u-ca=gregory]
#with Source
with :: forall fields rest. Union fields rest WithFields => Record fields -> PlainDate -> Effect PlainDateSame as withWithOptions with default options.
exampleWith :: Effect Unit
exampleWith = do
date <- PlainDate.fromString "2021-07-06"
lastDay <- PlainDate.with { day: PlainDate.daysInMonth date } date
Console.log (PlainDate.toString lastDay)
2021-07-31
#yearOfWeek Source
yearOfWeek :: PlainDate -> Maybe IntWeek-numbering year, if the calendar defines week numbering.
exampleYearOfWeek :: Effect Unit
exampleYearOfWeek = do
date <- PlainDate.fromString "2024-07-01"
Console.log ("Year of week: " <> show (PlainDate.yearOfWeek date))
Year of week: (Just 2024)
Re-exports from JS.Temporal.PlainDate.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