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 PlainYearMonthConstruct from year and month (1–12). Returns Nothing for invalid months.
#fromString Source
fromString :: String -> Maybe PlainYearMonthParse an ISO 8601 year-month string (e.g. "2024-03").
Returns Nothing for invalid strings.
#getYear Source
getYear :: PlainYearMonth -> IntCalendar year.
#getMonth Source
getMonth :: PlainYearMonth -> IntMonth of the year (1–12).
#getMonthCode Source
getMonthCode :: PlainYearMonth -> StringMonth code string (e.g. "M03" for March). Useful for non-ISO calendars.
#getDaysInMonth Source
getDaysInMonth :: PlainYearMonth -> IntNumber of days in this month (28–31).
#getDaysInYear Source
getDaysInYear :: PlainYearMonth -> IntNumber of days in this year (365 or 366).
#getMonthsInYear Source
getMonthsInYear :: PlainYearMonth -> IntAlways 12 for the ISO calendar.
#getInLeapYear Source
getInLeapYear :: PlainYearMonth -> BooleanWhether this year is a leap year.
#with Source
with :: { month :: Int, year :: Int } -> PlainYearMonth -> Maybe PlainYearMonthCreate a modified copy with the given year and month. Returns Nothing
if the result would be invalid.
#add Source
add :: Duration -> PlainYearMonth -> Maybe PlainYearMonthAdd a duration (only year and month components are meaningful).
Returns Nothing on overflow.
#subtract Source
subtract :: Duration -> PlainYearMonth -> Maybe PlainYearMonthSubtract 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 -> Durationsince opts a b returns the duration from b to a.
#until Source
until :: PlainYearMonthDiffOptions -> PlainYearMonth -> PlainYearMonth -> Durationuntil opts a b returns the duration from a to b.
#since' Source
since' :: PlainYearMonth -> PlainYearMonth -> Durationsince' a b — duration from b to a with default options.
#until' Source
until' :: PlainYearMonth -> PlainYearMonth -> Durationuntil' a b — duration from a to b with default options.
#toPlainDate Source
toPlainDate :: Int -> PlainYearMonth -> Maybe PlainDateConvert 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 -> StringSerialize to an ISO 8601 year-month string (e.g. "2024-03").
Re-exports from Temporal.Internal.Types
#PlainYearMonth Source
data PlainYearMonthA 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
#Duration Source
data DurationA 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 }.