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.
#new Source
new :: Int -> Int -> Effect PlainYearMonthCreates 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 PlainYearMonthCreates 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
#year Source
year :: PlainYearMonth -> IntISO calendar year number.
#month Source
month :: PlainYearMonth -> IntMonth number within the year.
#monthCode Source
monthCode :: PlainYearMonth -> StringCalendar-specific month code, such as M06.
#daysInMonth Source
daysInMonth :: PlainYearMonth -> IntNumber of days in the represented month.
#daysInYear Source
daysInYear :: PlainYearMonth -> IntNumber of days in the represented year.
#monthsInYear Source
monthsInYear :: PlainYearMonth -> IntNumber of months in the represented year for this calendar.
#inLeapYear Source
inLeapYear :: PlainYearMonth -> BooleanWhether the represented year is a leap year in this calendar.
#calendarId Source
calendarId :: PlainYearMonth -> StringCalendar identifier, such as "iso8601".
#eraYear Source
eraYear :: PlainYearMonth -> Maybe IntYear 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 PlainYearMonthAdds 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 PlainYearMonthSame as add with default options.
#subtract Source
subtract :: forall provided. ConvertOptionsWithDefaults ToOverflowOptions (Record OverflowOptions) (Record provided) (Record OverflowOptions) => Record provided -> Duration -> PlainYearMonth -> Effect PlainYearMonthSubtracts 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 PlainYearMonthSame 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 PlainYearMonthReturns 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 PlainYearMonthSame as with with default options.
#toPlainDate Source
toPlainDate :: { day :: Int } -> PlainYearMonth -> Effect PlainDateConverts 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 DurationDuration 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 DurationSame as until with default options.
#since Source
since :: forall provided. ConvertOptionsWithDefaults ToDifferenceOptions (Record DifferenceOptions) (Record provided) (Record DifferenceOptions) => Record provided -> PlainYearMonth -> PlainYearMonth -> Effect DurationDuration 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 DurationSame as since with default options.
#toString Source
toString :: forall provided. ConvertOptionsWithDefaults ToToStringOptions (Record ToStringOptions) (Record provided) (Record ToStringOptions) => Record provided -> PlainYearMonth -> StringSerializes to ISO 8601 year-month format. Options: calendarName.
yearMonth <- PlainYearMonth.from_ "2024-06"
Console.log (PlainYearMonth.toString {} yearMonth)
2024-06
#toString_ Source
toString_ :: PlainYearMonth -> StringSame as toString with default options.
#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