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

#new Source

new :: Int -> Int -> Effect PlainMonthDay

Creates a PlainMonthDay from month and day.

locale <- JS.Intl.Locale.new_ "en-US"
holiday <- PlainMonthDay.new 7 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. 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.from { 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

#from_ Source

from_ :: String -> Effect PlainMonthDay

Same as from 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.from_ "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.from_ "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.from_ "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