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
#add Source
add :: 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.
locale <- JS.Intl.Locale.new_ "en-US"
date <- PlainDate.from_ "2024-03-15"
oneWeek <- Duration.new { weeks: 1 }
later <- PlainDate.add { overflow: Overflow.Constrain } 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").
#daysInMonth Source
daysInMonth :: PlainDate -> IntNumber of days in the current month.
#daysInWeek Source
daysInWeek :: PlainDate -> IntNumber of days in the current week according to the calendar.
#daysInYear Source
daysInYear :: PlainDate -> IntNumber of days in the current year.
#from Source
from :: 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.
locale <- JS.Intl.Locale.new_ "en-US"
date <- PlainDate.from { overflow: Overflow.Constrain } "2024-01-15"
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter date)
January 15, 2024
#inLeapYear Source
inLeapYear :: PlainDate -> BooleanWhether the current year is a leap year in this calendar.
#monthsInYear Source
monthsInYear :: PlainDate -> IntNumber of months in the current year.
#new Source
new :: Int -> Int -> Int -> Effect PlainDateCreates a PlainDate from year, month, day (ISO calendar). Prefer
from for
most use cases. Throws if the date is invalid or out of representable range.
locale <- JS.Intl.Locale.new_ "en-US"
date <- PlainDate.new 2024 7 1
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter date)
July 1, 2024
#since Source
since :: forall provided. ConvertOptionsWithDefaults ToDifferenceOptions (Record DifferenceOptions) (Record provided) (Record DifferenceOptions) => Record provided -> PlainDate -> PlainDate -> Effect DurationDuration from other to subject (inverse of until). Arg order: since options other subject.
locale <- JS.Intl.Locale.new_ "en-US"
start <- PlainDate.from_ "2024-01-01"
end <- PlainDate.from_ "2024-03-15"
elapsed <- PlainDate.since { 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
#subtract Source
subtract :: forall provided. ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record provided) (Record OverflowOptions) => Record provided -> Duration -> PlainDate -> Effect PlainDateSubtracts a duration. Arg order: subtract options duration subject. Options: overflow.
locale <- JS.Intl.Locale.new_ "en-US"
date <- PlainDate.from_ "2024-03-15"
oneWeek <- Duration.new { weeks: 1 }
earlier <- PlainDate.subtract { overflow: Overflow.Constrain } 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.
date <- PlainDate.from_ "2024-01-15"
time <- PlainTime.from_ "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.
date <- PlainDate.from_ "2024-01-15"
Console.log (PlainMonthDay.toString_ (PlainDate.toPlainMonthDay date))
01-15
#toZonedDateTime Source
toZonedDateTime :: String -> PlainDate -> Effect ZonedDateTimeConverts to a ZonedDateTime at midnight in the given time zone.
date <- PlainDate.from_ "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.
date <- PlainDate.from_ "2024-01-15"
Console.log (PlainYearMonth.toString_ (PlainDate.toPlainYearMonth date))
2024-01
#toString Source
toString :: forall provided. ConvertOptionsWithDefaults ToToStringOptions (Record ToStringOptions) (Record provided) (Record ToStringOptions) => Record provided -> PlainDate -> StringSerializes to ISO 8601 date format. Options: calendarName.
date <- PlainDate.from_ "2024-01-15"
Console.log (PlainDate.toString { calendarName: CalendarName.Never } date)
2024-01-15
#until Source
until :: 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.
locale <- JS.Intl.Locale.new_ "en-US"
today <- Now.plainDateISO_
futureDate <- PlainDate.from_ "2026-12-25"
untilDuration <- PlainDate.until { smallestUnit: TemporalUnit.Day } futureDate today
formatter <- JS.Intl.DurationFormat.new [ locale ] { style: "long" }
Console.log (JS.Intl.DurationFormat.format formatter untilDuration <> " until Christmas 2026")
292 days until Christmas 2026
#weekOfYear Source
weekOfYear :: PlainDate -> Maybe IntWeek number within the year, if the calendar defines week numbering.
#with Source
with :: 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.
locale <- JS.Intl.Locale.new_ "en-US"
date <- PlainDate.from_ "2021-07-06"
lastDayOfMonth <- PlainDate.with { overflow: Overflow.Constrain } { day: PlainDate.daysInMonth date } date
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter lastDayOfMonth)
July 31, 2021
#withCalendar Source
withCalendar :: String -> PlainDate -> Effect PlainDateReturns a new PlainDate with the given calendar (for example "iso8601").
date <- PlainDate.from_ "2024-01-15"
gregory <- PlainDate.withCalendar "gregory" date
Console.log (PlainDate.toString { calendarName: CalendarName.Always } gregory)
2024-01-15[u-ca=gregory]
#yearOfWeek Source
yearOfWeek :: PlainDate -> Maybe IntWeek-numbering year, if the calendar defines week numbering.
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