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.
#PlainYearMonthComponents Source
type PlainYearMonthComponents :: Row Typetype PlainYearMonthComponents = (calendar :: String, era :: String, eraYear :: Int, month :: Int, monthCode :: String, year :: Int)
#fromWithOptions Source
fromWithOptions :: forall optsProvided provided rest. Union provided rest PlainYearMonthComponents => ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record optsProvided) (Record OverflowOptions) => Record optsProvided -> Record provided -> Effect PlainYearMonthCreates a PlainYearMonth from component fields. Options: overflow.
exampleFromWithOptions :: Effect Unit
exampleFromWithOptions = do
ym <- PlainYearMonth.fromWithOptions { overflow: Overflow.Constrain } { year: 2024, month: 6 }
Console.log (PlainYearMonth.toString ym)
2024-06
#from Source
from :: forall provided rest. Union provided rest PlainYearMonthComponents => Record provided -> Effect PlainYearMonthSame as fromWithOptions with default options.
exampleFrom :: Effect Unit
exampleFrom = do
locale <- JS.Intl.Locale.new_ "en-US"
yearMonth <- PlainYearMonth.from { year: 2024, month: 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
#fromStringWithOptions Source
fromStringWithOptions :: forall provided. ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record provided) (Record OverflowOptions) => Record provided -> String -> Effect PlainYearMonthCreates a PlainYearMonth from an RFC 9557 / ISO 8601 year-month string (e.g. "2024-01").
Options: overflow.
exampleFromStringWithOptions :: Effect Unit
exampleFromStringWithOptions = do
ym <- PlainYearMonth.fromStringWithOptions { overflow: Overflow.Constrain } "2024-06"
Console.log (PlainYearMonth.toString ym)
2024-06
#fromString Source
fromString :: String -> Effect PlainYearMonthSame as fromStringWithOptions with default options.
exampleFromString :: Effect Unit
exampleFromString = do
yearMonth <- PlainYearMonth.fromString "2024-06"
Console.log (PlainYearMonth.toString yearMonth)
2024-06
#year Source
year :: PlainYearMonth -> IntISO calendar year number.
exampleYear :: Effect Unit
exampleYear = do
ym <- PlainYearMonth.fromString "2024-06"
Console.log ("Year: " <> show (PlainYearMonth.year ym))
Year: 2024
#month Source
month :: PlainYearMonth -> IntMonth number within the year.
exampleMonth :: Effect Unit
exampleMonth = do
ym <- PlainYearMonth.fromString "2024-06"
Console.log ("Month: " <> show (PlainYearMonth.month ym))
Month: 6
#monthCode Source
monthCode :: PlainYearMonth -> StringCalendar-specific month code, such as M06.
exampleMonthCode :: Effect Unit
exampleMonthCode = do
ym <- PlainYearMonth.fromString "2024-06"
Console.log ("Month code: " <> PlainYearMonth.monthCode ym)
Month code: M06
#daysInMonth Source
daysInMonth :: PlainYearMonth -> IntNumber of days in the represented month.
exampleDaysInMonth :: Effect Unit
exampleDaysInMonth = do
ym <- PlainYearMonth.fromString "2024-02"
Console.log ("Days in Feb 2024: " <> show (PlainYearMonth.daysInMonth ym))
Days in Feb 2024: 29
#daysInYear Source
daysInYear :: PlainYearMonth -> IntNumber of days in the represented year.
exampleDaysInYear :: Effect Unit
exampleDaysInYear = do
ym <- PlainYearMonth.fromString "2024-06"
Console.log ("Days in 2024: " <> show (PlainYearMonth.daysInYear ym))
Days in 2024: 366
#monthsInYear Source
monthsInYear :: PlainYearMonth -> IntNumber of months in the represented year for this calendar.
exampleMonthsInYear :: Effect Unit
exampleMonthsInYear = do
ym <- PlainYearMonth.fromString "2024-06"
Console.log ("Months in year: " <> show (PlainYearMonth.monthsInYear ym))
Months in year: 12
#inLeapYear Source
inLeapYear :: PlainYearMonth -> BooleanWhether the represented year is a leap year in this calendar.
exampleInLeapYear :: Effect Unit
exampleInLeapYear = do
ym <- PlainYearMonth.fromString "2024-06"
Console.log ("2024 is leap year: " <> show (PlainYearMonth.inLeapYear ym))
2024 is leap year: true
#calendarId Source
calendarId :: PlainYearMonth -> StringCalendar identifier, such as "iso8601".
exampleCalendarId :: Effect Unit
exampleCalendarId = do
ym <- PlainYearMonth.fromString "2024-06"
Console.log ("Calendar: " <> PlainYearMonth.calendarId ym)
Calendar: iso8601
#era Source
era :: PlainYearMonth -> Maybe StringEra identifier when the calendar uses eras.
exampleEra :: Effect Unit
exampleEra = do
ym <- PlainYearMonth.fromString "2024-06"
Console.log ("Era: " <> show (PlainYearMonth.era ym))
Era: Nothing
#eraYear Source
eraYear :: PlainYearMonth -> Maybe IntYear number within the current era when available.
exampleEraYear :: Effect Unit
exampleEraYear = do
ym <- PlainYearMonth.fromString "2024-06"
Console.log ("Era year: " <> show (PlainYearMonth.eraYear ym))
Era year: Nothing
#addWithOptions Source
addWithOptions :: forall provided. ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record provided) (Record OverflowOptions) => Record provided -> Duration -> PlainYearMonth -> Effect PlainYearMonthAdds a duration. Options: overflow.
exampleAddWithOptions :: Effect Unit
exampleAddWithOptions = do
ym <- PlainYearMonth.fromString "2024-06"
threeMonths <- Duration.from { months: 3 }
later <- PlainYearMonth.addWithOptions { overflow: Overflow.Constrain } threeMonths ym
Console.log (PlainYearMonth.toString later)
2024-09
#add Source
add :: Duration -> PlainYearMonth -> Effect PlainYearMonthSame as addWithOptions with default options.
exampleAdd :: Effect Unit
exampleAdd = do
ym <- PlainYearMonth.fromString "2024-06"
threeMonths <- Duration.from { months: 3 }
later <- PlainYearMonth.add threeMonths ym
Console.log (PlainYearMonth.toString later)
2024-09
#subtractWithOptions Source
subtractWithOptions :: forall provided. ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record provided) (Record OverflowOptions) => Record provided -> Duration -> PlainYearMonth -> Effect PlainYearMonthSubtracts a duration. Options: overflow.
exampleSubtractWithOptions :: Effect Unit
exampleSubtractWithOptions = do
ym <- PlainYearMonth.fromString "2024-06"
twoMonths <- Duration.from { months: 2 }
earlier <- PlainYearMonth.subtractWithOptions { overflow: Overflow.Constrain } twoMonths ym
Console.log (PlainYearMonth.toString earlier)
2024-04
#subtract Source
subtract :: Duration -> PlainYearMonth -> Effect PlainYearMonthSame as subtractWithOptions with default options.
exampleSubtract :: Effect Unit
exampleSubtract = do
ym <- PlainYearMonth.fromString "2024-06"
twoMonths <- Duration.from { months: 2 }
earlier <- PlainYearMonth.subtract twoMonths ym
Console.log (PlainYearMonth.toString earlier)
2024-04
#withWithOptions Source
withWithOptions :: forall optsProvided fields rest. Union fields rest WithFields => ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record optsProvided) (Record OverflowOptions) => Record optsProvided -> Record fields -> PlainYearMonth -> Effect PlainYearMonthReturns a new PlainYearMonth with specified fields replaced. Options: overflow.
exampleWithWithOptions :: Effect Unit
exampleWithWithOptions = do
ym <- PlainYearMonth.fromString "2024-06"
changed <- PlainYearMonth.withWithOptions { overflow: Overflow.Constrain } { month: 12 } ym
Console.log (PlainYearMonth.toString changed)
2024-12
#with Source
with :: forall fields rest. Union fields rest WithFields => Record fields -> PlainYearMonth -> Effect PlainYearMonthSame as withWithOptions with default options.
exampleWith :: Effect Unit
exampleWith = do
ym <- PlainYearMonth.fromString "2024-06"
changed <- PlainYearMonth.with { month: 12 } ym
Console.log (PlainYearMonth.toString changed)
2024-12
#toPlainDate Source
toPlainDate :: { day :: Int } -> PlainYearMonth -> Effect PlainDateConverts to PlainDate by supplying a day.
exampleToPlainDate :: Effect Unit
exampleToPlainDate = do
locale <- JS.Intl.Locale.new_ "en-US"
yearMonth <- PlainYearMonth.fromString "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
#untilWithOptions Source
untilWithOptions :: forall provided. ConvertOptionsWithDefaults ToDifferenceOptions (Record DifferenceOptions) (Record provided) (Record DifferenceOptions) => Record provided -> PlainYearMonth -> PlainYearMonth -> Effect DurationDuration from subject (last arg) until other (second arg). Arg order: untilWithOptions options other subject.
exampleUntilWithOptions :: Effect Unit
exampleUntilWithOptions = do
locale <- JS.Intl.Locale.new_ "en-US"
start <- PlainYearMonth.fromString "2024-01"
end <- PlainYearMonth.fromString "2025-06"
duration <- PlainYearMonth.untilWithOptions { 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 DurationSame as untilWithOptions with default options.
exampleUntil :: Effect Unit
exampleUntil = do
start <- PlainYearMonth.fromString "2024-01"
end <- PlainYearMonth.fromString "2025-06"
duration <- PlainYearMonth.until end start
Console.log (Duration.toString duration)
P1Y5M
#sinceWithOptions Source
sinceWithOptions :: forall provided. ConvertOptionsWithDefaults ToDifferenceOptions (Record DifferenceOptions) (Record provided) (Record DifferenceOptions) => Record provided -> PlainYearMonth -> PlainYearMonth -> Effect DurationDuration from other to subject (inverse of untilWithOptions). Arg order: sinceWithOptions options other subject.
exampleSinceWithOptions :: Effect Unit
exampleSinceWithOptions = do
locale <- JS.Intl.Locale.new_ "en-US"
earlier <- PlainYearMonth.fromString "2022-06"
later <- PlainYearMonth.fromString "2024-06"
duration <- PlainYearMonth.sinceWithOptions { 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 DurationSame as sinceWithOptions with default options.
exampleSince :: Effect Unit
exampleSince = do
earlier <- PlainYearMonth.fromString "2022-06"
later <- PlainYearMonth.fromString "2024-06"
duration <- PlainYearMonth.since earlier later
Console.log (Duration.toString duration)
P2Y
#toStringWithOptions Source
toStringWithOptions :: forall provided. ConvertOptionsWithDefaults ToToStringOptions (Record ToStringOptions) (Record provided) (Record ToStringOptions) => Record provided -> PlainYearMonth -> StringSerializes to ISO 8601 year-month format. Options: calendarName.
exampleToStringWithOptions :: Effect Unit
exampleToStringWithOptions = do
ym <- PlainYearMonth.fromString "2024-06"
Console.log (PlainYearMonth.toStringWithOptions {} ym)
2024-06
#toString Source
toString :: PlainYearMonth -> StringSame as toStringWithOptions with default options.
exampleToString :: Effect Unit
exampleToString = do
ym <- PlainYearMonth.fromString "2024-06"
Console.log (PlainYearMonth.toString ym)
2024-06
#ToOverflowOptions Source
data ToOverflowOptionsInstances
ConvertOption ToOverflowOptions "overflow" Overflow StringConvertOption ToOverflowOptions "overflow" String String
#ToDifferenceOptions Source
data ToDifferenceOptionsInstances
ConvertOption ToDifferenceOptions "largestUnit" TemporalUnit StringConvertOption ToDifferenceOptions "largestUnit" String StringConvertOption ToDifferenceOptions "smallestUnit" TemporalUnit StringConvertOption ToDifferenceOptions "smallestUnit" String StringConvertOption ToDifferenceOptions "roundingIncrement" Int IntConvertOption ToDifferenceOptions "roundingMode" RoundingMode StringConvertOption ToDifferenceOptions "roundingMode" String String
#ToToStringOptions Source
data ToToStringOptionsInstances
ConvertOption ToToStringOptions "calendarName" CalendarName StringConvertOption ToToStringOptions "calendarName" String String
Re-exports from JS.Temporal.PlainYearMonth.Internal
- Modules
- JS.
Temporal. Duration - JS.
Temporal. Duration. Internal - JS.
Temporal. Instant - JS.
Temporal. Instant. Internal - JS.
Temporal. Internal - JS.
Temporal. Now - JS.
Temporal. Options. CalendarName - JS.
Temporal. Options. Disambiguation - JS.
Temporal. Options. OffsetDisambiguation - JS.
Temporal. Options. Overflow - JS.
Temporal. Options. RoundingMode - JS.
Temporal. Options. TemporalUnit - JS.
Temporal. PlainDate - JS.
Temporal. PlainDate. Internal - JS.
Temporal. PlainDateTime - JS.
Temporal. PlainDateTime. Internal - JS.
Temporal. PlainMonthDay - JS.
Temporal. PlainMonthDay. Internal - JS.
Temporal. PlainTime - JS.
Temporal. PlainTime. Internal - JS.
Temporal. PlainYearMonth - JS.
Temporal. PlainYearMonth. Internal - JS.
Temporal. ZonedDateTime - JS.
Temporal. ZonedDateTime. Internal