Module

Temporal.PlainYearMonth

Package
purescript-temporal
Repository
philippedev101/purescript-temporal

Construction, arithmetic, and inspection of PlainYearMonth values.

A PlainYearMonth represents a year and month without a day component (e.g. 2024-03). Useful for calendar month views, credit card expiry dates, or any context where the specific day is irrelevant.

#plainYearMonth Source

plainYearMonth :: Int -> Int -> Maybe PlainYearMonth

Construct from year and month (1–12). Returns Nothing for invalid months.

#fromString Source

fromString :: String -> Maybe PlainYearMonth

Parse an ISO 8601 year-month string (e.g. "2024-03"). Returns Nothing for invalid strings.

#getYear Source

getYear :: PlainYearMonth -> Int

Calendar year.

#getMonth Source

getMonth :: PlainYearMonth -> Int

Month of the year (1–12).

#getMonthCode Source

getMonthCode :: PlainYearMonth -> String

Month code string (e.g. "M03" for March). Useful for non-ISO calendars.

#getDaysInMonth Source

getDaysInMonth :: PlainYearMonth -> Int

Number of days in this month (28–31).

#getDaysInYear Source

getDaysInYear :: PlainYearMonth -> Int

Number of days in this year (365 or 366).

#getMonthsInYear Source

getMonthsInYear :: PlainYearMonth -> Int

Always 12 for the ISO calendar.

#getInLeapYear Source

getInLeapYear :: PlainYearMonth -> Boolean

Whether this year is a leap year.

#with Source

with :: { month :: Int, year :: Int } -> PlainYearMonth -> Maybe PlainYearMonth

Create a modified copy with the given year and month. Returns Nothing if the result would be invalid.

#add Source

add :: Duration -> PlainYearMonth -> Maybe PlainYearMonth

Add a duration (only year and month components are meaningful). Returns Nothing on overflow.

#subtract Source

subtract :: Duration -> PlainYearMonth -> Maybe PlainYearMonth

Subtract a duration. Returns Nothing on overflow.

#PlainYearMonthDiffOptions Source

type PlainYearMonthDiffOptions = { largestUnit :: DateUnit, roundingIncrement :: Int, roundingMode :: RoundingMode, smallestUnit :: DateUnit }

Options for since and until. Default: largest unit is Years, smallest unit is Months.

#since Source

since :: PlainYearMonthDiffOptions -> PlainYearMonth -> PlainYearMonth -> Duration

since opts a b returns the duration from b to a.

#until Source

until :: PlainYearMonthDiffOptions -> PlainYearMonth -> PlainYearMonth -> Duration

until opts a b returns the duration from a to b.

#since' Source

since' :: PlainYearMonth -> PlainYearMonth -> Duration

since' a b — duration from b to a with default options.

#until' Source

until' :: PlainYearMonth -> PlainYearMonth -> Duration

until' a b — duration from a to b with default options.

#toPlainDate Source

toPlainDate :: Int -> PlainYearMonth -> Maybe PlainDate

Convert to a PlainDate by specifying a day. Out-of-range days are constrained — e.g. toPlainDate 31 on February yields Feb 28 or 29. Returns Nothing for truly invalid values.

#toString Source

toString :: PlainYearMonth -> String

Serialize to an ISO 8601 year-month string (e.g. "2024-03").

Re-exports from Temporal.Internal.Types

#PlainYearMonth Source

data PlainYearMonth

A year and month without a day component (e.g. 2024-03).

Useful for representing months in a calendar UI or credit card expiry dates.

Instances

#PlainDate Source

data PlainDate

A calendar date without a time component or time zone (e.g. 2024-03-15).

Use PlainDate for birthdays, holidays, and other dates where time of day is irrelevant. Do not use for scheduling events — use ZonedDateTime instead.

Instances

#Duration Source

data Duration

A length of time expressed as a combination of date and time components (years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds). All components must share the same sign.

Durations are unbalanced{ hours: 36 } is not automatically converted to { days: 1, hours: 12 }. Use round to balance.

Eq compares component-by-component (not total elapsed time), so { hours: 1 } is not equal to { minutes: 60 }.

Instances