Skip to contents

A plain_year_month() is a month of a year in the ISO 8601 calendar, stored as an integer count of months since January 1970. The constructor is Temporal.PlainYearMonth and Temporal.PlainYearMonth.from() in one: it reads fields, strings or a plain_date() or plain_date_time().

Usage

plain_year_month(
  year,
  month = NULL,
  ...,
  month_code = NULL,
  overflow = "constrain"
)

plain_year_month_compare(x, y)

Arguments

year

The year, or a string in ISO 8601 form ("2026-03", "202603", or a full date or date-time whose day and time are ignored), or a plain_year_month(), plain_date() or plain_date_time() to convert.

month

The month (1 to 12), when year is a number. May be replaced by month_code.

...

Must be empty.

month_code

The month as "M01" to "M12", instead of month.

overflow

"constrain" (the default) clamps month to 1 to 12, "reject" raises a zutempo_range_error.

x, y

plain_year_month() values or strings, for plain_year_month_compare().

Value

A plain_year_month() vector; plain_year_month_compare() returns an integer vector of -1, 0 and 1.

Details

Months run from -271821-04 to +275760-09, every month that holds a representable plain_date().

Members

Every member of Temporal.PlainYearMonth in the pinned specification (inst/spec/PINS) and the R function that implements it:

TemporalR
new Temporal.PlainYearMonth()plain_year_month()
Temporal.PlainYearMonth.from()plain_year_month()
Temporal.PlainYearMonth.compare()plain_year_month_compare()
.calendarIdcalendar_id()
.eraera()
.eraYearera_year()
.yearyear()
.monthmonth()
.monthCodemonth_code()
.daysInYeardays_in_year()
.daysInMonthdays_in_month()
.monthsInYearmonths_in_year()
.inLeapYearin_leap_year()
.with()temporal_with()
.add()temporal_add()
.subtract()temporal_subtract()
.until()temporal_until()
.since()temporal_since()
.equals()temporal_equals()
.toString()temporal_to_string()
.toLocaleString()none: ECMA-402 (locale formatting) is out of scope
.toJSON()none: format() covers it
.valueOf()none: throws in JavaScript; no R counterpart
.toPlainDate()temporal_to_plain_date()

Examples

plain_year_month("2026-03")
#> <zutempo_plain_year_month[1]>
#> [1] 2026-03
plain_year_month(2026, 3)
#> <zutempo_plain_year_month[1]>
#> [1] 2026-03
plain_year_month(plain_date("2026-03-15"))
#> <zutempo_plain_year_month[1]>
#> [1] 2026-03
temporal_to_plain_date(plain_year_month("2026-02"), day = 31)
#> <zutempo_plain_date[1]>
#> [1] 2026-02-28
plain_year_month_compare("2026-02", "2026-03")
#> [1] -1