A Iso.YearMonth represents a particular month on the calendar. For example, it could be used to represent a particular instance of a monthly recurring event, like "the June 2019 meeting".
Iso.YearMonth refers to the whole of a specific month; if you need to refer to a calendar event on a certain day, use Iso.Date or even Iso.DateTime. A Iso.YearMonth can be converted into a Iso.Date by combining it with a day of the month, using the toDate() function.
fromNumbers()
fromNumbers(
year,month):YearMonth
Parameters
year
number
month
number
Returns
isValid()
isValid(
yearMonth):yearMonth is YearMonth
Parameters
yearMonth
unknown
Returns
yearMonth is YearMonth
assertIsValid()
assertIsValid(
yearMonth):asserts yearMonth is YearMonth
Parameters
yearMonth
unknown
Returns
asserts yearMonth is YearMonth
getYear()
getYear(
yearMonth):number
Parameters
yearMonth
Returns
number
getMonth()
getMonth(
yearMonth):number
Parameters
yearMonth
Returns
number
getDaysInMonth()
getDaysInMonth(
yearMonth):number
Parameters
yearMonth
Returns
number
getDaysInYear()
getDaysInYear(
yearMonth):number
Parameters
yearMonth
Returns
number
inLeapYear()
inLeapYear(
yearMonth):boolean
Parameters
yearMonth
Returns
boolean
with()
with(
yearMonth,yearMonthLike,options?):YearMonth
Parameters
yearMonth
yearMonthLike
year?
number
month?
number
options?
overflow
"constrain" | "reject"
Returns
add()
add(
yearMonth,temporalDurationLike,options?):YearMonth
Parameters
yearMonth
temporalDurationLike
Duration | { years?: number; months?: number; weeks?: number; days?: number; hours?: number; minutes?: number; seconds?: number; milliseconds?: number; }
options?
overflow?
"constrain" | "reject"
Returns
subtract()
subtract(
yearMonth,temporalDurationLike,options?):YearMonth
Parameters
yearMonth
temporalDurationLike
Duration | { years?: number; months?: number; weeks?: number; days?: number; hours?: number; minutes?: number; seconds?: number; milliseconds?: number; }
options?
overflow?
"constrain" | "reject"
Returns
until()
until(
yearMonth,other,options?):Duration
Parameters
yearMonth
other
options?
largestUnit?
LargestUnit\<"month" | "year">
smallestUnit?
SmallestUnit\<"month" | "year">
roundingIncrement?
number
roundingMode?
RoundingMode
Returns
since()
since(
yearMonth,other,options?):Duration
Parameters
yearMonth
other
options?
largestUnit?
LargestUnit\<"month" | "year">
smallestUnit?
SmallestUnit\<"month" | "year">
roundingIncrement?
number
roundingMode?
RoundingMode
Returns
equals()
equals(
yearMonth,other):boolean
Parameters
yearMonth
other
Returns
boolean
isEqual()
isEqual(
yearMonth,other):boolean
alias for equals
Parameters
yearMonth
other
Returns
boolean
isBefore()
isBefore(
yearMonth,other):boolean
Parameters
yearMonth
other
Returns
boolean
isAfter()
isAfter(
yearMonth,other):boolean
Parameters
yearMonth
other
Returns
boolean
isEqualOrBefore()
isEqualOrBefore(
yearMonth,other):boolean
Parameters
yearMonth
other
Returns
boolean
isEqualOrAfter()
isEqualOrAfter(
yearMonth,other):boolean
Parameters
yearMonth
other
Returns
boolean
toDate()
toDate(
yearMonth,day):Date
Parameters
yearMonth
day
number
Returns
getFields()
getFields(
yearMonth):YearMonthSlots
Parameters
yearMonth
Returns
YearMonthSlots
from()
from(
item,options?):YearMonth
Parameters
item
string | Partial\<YearMonthSlots>
options?
overflow
"constrain" | "reject"
Returns
compare()
compare(
one,two):number
Parameters
one
two
Returns
number
format()
format(
yearMonth,format,options?):string
Parameters
yearMonth
the original date
format
string
the string of tokens
options?
FormatOptions
Returns
string
the formatted date string
Description
Return the formatted ZonedDateTime string in the given format.
The characters wrapped between two single quotes characters (') are escaped. Two single quotes in a row, whether inside or outside a quoted sequence, represent a 'real' single quote. (see the last example)
Format of the string is based on Unicode Technical Standard #35: https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table with a few additions (see note 7 below the table).
Accepted patterns:
| Unit | Pattern | Result examples | Notes |
|---|---|---|---|
| Era | G..GGG | AD, BC | |
| GGGG | Anno Domini, Before Christ | 1 | |
| GGGGG | A, B | ||
| Calendar year | y | 44, 1, 1900, 2017 | 4 |
| yo | 44th, 1st, 0th, 17th | 4,5 | |
| yy | 44, 01, 00, 17 | 4 | |
| yyy | 044, 001, 1900, 2017 | 4 | |
| yyyy | 0044, 0001, 1900, 2017 | 4 | |
| yyyyy | ... | 2,4 | |
| Extended year | u | -43, 0, 1, 1900, 2017 | 4 |
| uu | -43, 01, 1900, 2017 | 4 | |
| uuu | -043, 001, 1900, 2017 | 4 | |
| uuuu | -0043, 0001, 1900, 2017 | 4 | |
| uuuuu | ... | 2,4 | |
| Quarter | Q | 1, 2, 3, 4 | |
| Qo | 1st, 2nd, 3rd, 4th | 5 | |
| 01, 02, 03, 04 | |||
| QQQ | Q1, Q2, Q3, Q4 | ||
| QQQQ | 1st quarter, 2nd quarter, ... | 1 | |
| QQQQQ | 1, 2, 3, 4 | 3 | |
| Month | M | 1, 2, ..., 12 | |
| Mo | 1st, 2nd, ..., 12th | 5 | |
| MM | 01, 02, ..., 12 | ||
| MMM | Jan, Feb, ..., Dec | ||
| MMMM | January, February, ..., December | 1 | |
| MMMMM | J, F, ..., D |
Notes:
Any sequence of the identical letters is a pattern, unless it is escaped by the single quote characters (see below). If the sequence is longer than listed in table (e.g.
EEEEEEEEEEE) the output will be the same as default pattern for this unit, usually the longest one (in case of ISO weekdays,EEEE). Default patterns for units are marked with "2" in the last column of the table.format("2017-11-06", 'MMM') //=> 'Nov'format("2017-11-06", 'MMMM') //=> 'November'format("2017-11-06", 'MMMMM') //=> 'N'format("2017-11-06", 'MMMMMM') //=> 'November'format("2017-11-06", 'MMMMMMM') //=> 'November'Some patterns could be unlimited length (such as
yyyyyyyy). The output will be padded with zeros to match the length of the pattern.format("2017-11-06", 'yyyyyyyy') //=> '00002017'QQQQQcould be not strictly numerical in some locales. These tokens represent the shortest form of the quarter.The main difference between
yandupatterns are B.C. years:Year yuAC 1 1 1 BC 1 1 0 BC 2 2 -1 Also
yyalways returns the last two digits of a year, whileuupads single digit years to 2 characters and returns other years unchanged:Year yyuu1 01 01 14 14 14 376 76 376 1453 53 1453 These patterns are not in the Unicode Technical Standard #35:
o: ordinal number modifier
- Characters are escaped using single quote symbols (
').
Example
// Represent 11 February 2014 in middle-endian format:
var result = format("2014-02", 'MM/yyyy')
//=> '02/2014'
chain()
chain(
yearMonth):IYearMonthChain
Parameters
yearMonth
Returns
IYearMonthChain