Module

JS.Temporal.PlainYearMonth

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

A year and month without day or time zone. Use for month-level values (e.g. "January 2024"). Requires a reference day for some operations.

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

#new Source

new :: Int -> Int -> Effect PlainYearMonth

Creates a PlainYearMonth from year and month.

locale <- JS.Intl.Locale.new_ "en-US"
yearMonth <- PlainYearMonth.new 2024 6
firstDay <- PlainYearMonth.toPlainDate { day: 1 } yearMonth
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter firstDay)
June 1, 2024

#from Source

from :: forall provided. ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record provided) (Record OverflowOptions) => Record provided -> String -> Effect PlainYearMonth

Creates a PlainYearMonth from an RFC 9557 / ISO 8601 year-month string (e.g. "2024-01"). Options: overflow.

locale <- JS.Intl.Locale.new_ "en-US"
yearMonth <- PlainYearMonth.from { overflow: Overflow.Constrain } "2024-06"
firstDay <- PlainYearMonth.toPlainDate { day: 1 } yearMonth
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter firstDay)
June 1, 2024

#from_ Source

from_ :: String -> Effect PlainYearMonth

Same as from with default options.

#year Source

year :: PlainYearMonth -> Int

ISO calendar year number.

#month Source

month :: PlainYearMonth -> Int

Month number within the year.

#monthCode Source

monthCode :: PlainYearMonth -> String

Calendar-specific month code, such as M06.

#daysInMonth Source

daysInMonth :: PlainYearMonth -> Int

Number of days in the represented month.

#daysInYear Source

daysInYear :: PlainYearMonth -> Int

Number of days in the represented year.

#monthsInYear Source

monthsInYear :: PlainYearMonth -> Int

Number of months in the represented year for this calendar.

#inLeapYear Source

inLeapYear :: PlainYearMonth -> Boolean

Whether the represented year is a leap year in this calendar.

#calendarId Source

calendarId :: PlainYearMonth -> String

Calendar identifier, such as "iso8601".

#era Source

era :: PlainYearMonth -> Maybe String

Era identifier when the calendar uses eras.

#eraYear Source

eraYear :: PlainYearMonth -> Maybe Int

Year number within the current era when available.

#add Source

add :: forall provided. ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record provided) (Record OverflowOptions) => Record provided -> Duration -> PlainYearMonth -> Effect PlainYearMonth

Adds a duration. Options: overflow.

locale <- JS.Intl.Locale.new_ "en-US"
yearMonth <- PlainYearMonth.from_ "2024-06"
threeMonths <- Duration.new { months: 3 }
later <- PlainYearMonth.add { overflow: Overflow.Constrain } threeMonths yearMonth
firstDay <- PlainYearMonth.toPlainDate { day: 1 } later
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter firstDay)
September 1, 2024

#add_ Source

add_ :: Duration -> PlainYearMonth -> Effect PlainYearMonth

Same as add with default options.

#subtract Source

subtract :: forall provided. ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record provided) (Record OverflowOptions) => Record provided -> Duration -> PlainYearMonth -> Effect PlainYearMonth

Subtracts a duration. Options: overflow.

locale <- JS.Intl.Locale.new_ "en-US"
yearMonth <- PlainYearMonth.from_ "2024-06"
twoMonths <- Duration.new { months: 2 }
earlier <- PlainYearMonth.subtract { overflow: Overflow.Constrain } twoMonths yearMonth
firstDay <- PlainYearMonth.toPlainDate { day: 1 } earlier
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter firstDay)
April 1, 2024

#subtract_ Source

subtract_ :: Duration -> PlainYearMonth -> Effect PlainYearMonth

Same as subtract with default options.

#with Source

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

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

locale <- JS.Intl.Locale.new_ "en-US"
yearMonth <- PlainYearMonth.from_ "2024-06"
changed <- PlainYearMonth.with { overflow: Overflow.Constrain } { month: 12 } yearMonth
firstDay <- PlainYearMonth.toPlainDate { day: 1 } changed
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter firstDay)
December 1, 2024

#with_ Source

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

Same as with with default options.

#toPlainDate Source

toPlainDate :: { day :: Int } -> PlainYearMonth -> Effect PlainDate

Converts to PlainDate by supplying a day.

locale <- JS.Intl.Locale.new_ "en-US"
yearMonth <- PlainYearMonth.from_ "2024-01"
firstDay <- PlainYearMonth.toPlainDate { day: 1 } yearMonth
formatter <- JS.Intl.DateTimeFormat.new [ locale ] { dateStyle: "long" }
Console.log (JS.Intl.DateTimeFormat.format formatter firstDay)
January 1, 2024

#until Source

until :: forall provided. ConvertOptionsWithDefaults ToDifferenceOptions (Record DifferenceOptions) (Record provided) (Record DifferenceOptions) => Record provided -> PlainYearMonth -> PlainYearMonth -> Effect Duration

Duration from subject (last arg) until other (second arg). Arg order: until options other subject.

locale <- JS.Intl.Locale.new_ "en-US"
start <- PlainYearMonth.from_ "2024-01"
end <- PlainYearMonth.from_ "2025-06"
duration <- PlainYearMonth.until { largestUnit: TemporalUnit.Year } end start
formatter <- JS.Intl.DurationFormat.new [ locale ] { style: "long" }
Console.log (JS.Intl.DurationFormat.format formatter duration)
1 year, 5 months

#until_ Source

until_ :: PlainYearMonth -> PlainYearMonth -> Effect Duration

Same as until with default options.

#since Source

since :: forall provided. ConvertOptionsWithDefaults ToDifferenceOptions (Record DifferenceOptions) (Record provided) (Record DifferenceOptions) => Record provided -> PlainYearMonth -> PlainYearMonth -> Effect Duration

Duration from other to subject (inverse of until). Arg order: since options other subject.

locale <- JS.Intl.Locale.new_ "en-US"
earlier <- PlainYearMonth.from_ "2022-06"
later <- PlainYearMonth.from_ "2024-06"
duration <- PlainYearMonth.since { largestUnit: TemporalUnit.Year } earlier later
formatter <- JS.Intl.DurationFormat.new [ locale ] { style: "long" }
Console.log (JS.Intl.DurationFormat.format formatter duration)
2 years

#since_ Source

since_ :: PlainYearMonth -> PlainYearMonth -> Effect Duration

Same as since with default options.

#toString Source

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

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

yearMonth <- PlainYearMonth.from_ "2024-06"
Console.log (PlainYearMonth.toString {} yearMonth)
2024-06

#toString_ Source

toString_ :: PlainYearMonth -> String

Same as toString with default options.

Re-exports from JS.Temporal.PlainYearMonth.Internal