Module

JS.Temporal.PlainMonthDay

Package
purescript-js-temporal
Repository
pete-murphy/purescript-js-temporal

A month and day without year or time zone. Use for recurring dates (e.g. birthdays, annual events). Requires a year for conversion to PlainDate.

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/PlainMonthDay

#PlainMonthDayComponents Source

type PlainMonthDayComponents :: Row Typetype PlainMonthDayComponents = (calendar :: String, day :: Int, era :: String, eraYear :: Int, month :: Int, monthCode :: String, year :: Int)

#from Source

from :: forall optsProvided provided rest. Union provided rest PlainMonthDayComponents => ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record optsProvided) (Record OverflowOptions) => Record optsProvided -> Record provided -> Effect PlainMonthDay

Creates a PlainMonthDay from component fields. Options: overflow.

locale <- JS.Intl.Locale.new_ "en-US"
holiday <- PlainMonthDay.from_ { month: 7, day: 4 }
holidayIn2024 <- PlainMonthDay.toPlainDate { year: 2024 } holiday
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter holidayIn2024)
July 4, 2024

#from_ Source

from_ :: forall provided rest. Union provided rest PlainMonthDayComponents => Record provided -> Effect PlainMonthDay

Same as from with default options.

locale <- JS.Intl.Locale.new_ "en-US"
holiday <- PlainMonthDay.from_ { month: 7, day: 4 }
holidayIn2024 <- PlainMonthDay.toPlainDate { year: 2024 } holiday
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter holidayIn2024)
July 4, 2024

#fromString Source

fromString :: forall provided. ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record provided) (Record OverflowOptions) => Record provided -> String -> Effect PlainMonthDay

Creates a PlainMonthDay from an RFC 9557 / ISO 8601 month-day string (e.g. "12-15" or "--01-15"). Options: overflow.

locale <- JS.Intl.Locale.new_ "en-US"
birthday <- PlainMonthDay.fromString { overflow: Overflow.Constrain } "12-15"
birthdayIn2024 <- PlainMonthDay.toPlainDate { year: 2024 } birthday
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log ("Birthday: " <> JS.Intl.DateTimeFormat.format formatter birthdayIn2024)
Birthday: December 15, 2024

#fromString_ Source

fromString_ :: String -> Effect PlainMonthDay

Same as fromString with default options.

#monthCode Source

monthCode :: PlainMonthDay -> String

Calendar-specific month code, such as M12.

#day Source

day :: PlainMonthDay -> Int

Day of the month.

#calendarId Source

calendarId :: PlainMonthDay -> String

Calendar identifier, such as "iso8601".

#with Source

with :: forall optsProvided fields rest. Union fields rest WithFields => ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record optsProvided) (Record OverflowOptions) => Record optsProvided -> Record fields -> PlainMonthDay -> Effect PlainMonthDay

Returns a new PlainMonthDay with specified fields replaced. Options: overflow.

locale <- JS.Intl.Locale.new_ "en-US"
original <- PlainMonthDay.fromString_ "01-15"
changed <- PlainMonthDay.with { overflow: Overflow.Constrain } { day: 31 } original
changedIn2024 <- PlainMonthDay.toPlainDate { year: 2024 } changed
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter changedIn2024)
January 31, 2024

#with_ Source

with_ :: forall fields rest. Union fields rest WithFields => Record fields -> PlainMonthDay -> Effect PlainMonthDay

Same as with with default options.

#toPlainDate Source

toPlainDate :: { year :: Int } -> PlainMonthDay -> Effect PlainDate

Converts to PlainDate by supplying a year.

locale <- JS.Intl.Locale.new_ "en-US"
birthday <- PlainMonthDay.fromString_ "12-15"
birthdayIn2030 <- PlainMonthDay.toPlainDate { year: 2030 } birthday
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log ("Birthday in 2030: " <> JS.Intl.DateTimeFormat.format formatter birthdayIn2030)
Birthday in 2030: December 15, 2030

#toString Source

toString :: forall provided. ConvertOptionsWithDefaults ToToStringOptions (Record ToStringOptions) (Record provided) (Record ToStringOptions) => Record provided -> PlainMonthDay -> String

Serializes to ISO 8601 month-day format. Options: calendarName.

mday <- PlainMonthDay.fromString_ "03-14"
Console.log (PlainMonthDay.toString {} mday)
03-14

#toString_ Source

toString_ :: PlainMonthDay -> String

Same as toString with default options.

Re-exports from JS.Temporal.PlainMonthDay.Internal