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)

#fromWithOptions Source

fromWithOptions :: 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.

exampleFromWithOptions :: Effect Unit
exampleFromWithOptions = do
  holiday <- PlainMonthDay.fromWithOptions { overflow: Overflow.Constrain } { month: 7, day: 4 }
  Console.log (PlainMonthDay.toString holiday)

07-04

#from Source

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

Same as fromWithOptions with default options.

exampleFrom :: Effect Unit
exampleFrom = do
  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

#fromStringWithOptions Source

fromStringWithOptions :: 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.

exampleFromStringWithOptions :: Effect Unit
exampleFromStringWithOptions = do
  birthday <- PlainMonthDay.fromStringWithOptions { overflow: Overflow.Constrain } "12-15"
  Console.log (PlainMonthDay.toString birthday)

12-15

#fromString Source

fromString :: String -> Effect PlainMonthDay

Same as fromStringWithOptions with default options.

exampleFromString :: Effect Unit
exampleFromString = do
  birthday <- PlainMonthDay.fromString "12-15"
  Console.log (PlainMonthDay.toString birthday)

12-15

#monthCode Source

monthCode :: PlainMonthDay -> String

Calendar-specific month code, such as M12.

exampleMonthCode :: Effect Unit
exampleMonthCode = do
  mday <- PlainMonthDay.fromString "03-14"
  Console.log ("Month code: " <> PlainMonthDay.monthCode mday)

Month code: M03

#day Source

day :: PlainMonthDay -> Int

Day of the month.

exampleDay :: Effect Unit
exampleDay = do
  mday <- PlainMonthDay.fromString "03-14"
  Console.log ("Day: " <> show (PlainMonthDay.day mday))

Day: 14

#calendarId Source

calendarId :: PlainMonthDay -> String

Calendar identifier, such as "iso8601".

exampleCalendarId :: Effect Unit
exampleCalendarId = do
  mday <- PlainMonthDay.fromString "03-14"
  Console.log ("Calendar: " <> PlainMonthDay.calendarId mday)

Calendar: iso8601

#withWithOptions Source

withWithOptions :: 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.

exampleWithWithOptions :: Effect Unit
exampleWithWithOptions = do
  original <- PlainMonthDay.fromString "01-15"
  changed <- PlainMonthDay.withWithOptions { overflow: Overflow.Constrain } { day: 31 } original
  Console.log (PlainMonthDay.toString changed)

01-31

#with Source

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

Same as withWithOptions with default options.

exampleWith :: Effect Unit
exampleWith = do
  original <- PlainMonthDay.fromString "01-15"
  changed <- PlainMonthDay.with { day: 28 } original
  Console.log (PlainMonthDay.toString changed)

01-28

#toPlainDate Source

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

Converts to PlainDate by supplying a year.

exampleToPlainDate :: Effect Unit
exampleToPlainDate = do
  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

#toStringWithOptions Source

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

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

exampleToStringWithOptions :: Effect Unit
exampleToStringWithOptions = do
  mday <- PlainMonthDay.fromString "03-14"
  Console.log (PlainMonthDay.toStringWithOptions {} mday)

03-14

#toString Source

toString :: PlainMonthDay -> String

Same as toStringWithOptions with default options.

exampleToString :: Effect Unit
exampleToString = do
  mday <- PlainMonthDay.fromString "03-14"
  Console.log (PlainMonthDay.toString mday)

03-14

Re-exports from JS.Temporal.PlainMonthDay.Internal