YearMonth
Extends:
A year-month in the ISO-8601 calendar system, such as 2007-12
.
YearMonth is an immutable date-time object that represents the combination of a year and month. Any field that can be derived from a year and month, such as quarter-of-year, can be obtained.
This class does not store or represent a day, time or time-zone. For example, the value "October 2007" can be stored in a YearMonth.
The ISO-8601 calendar system is the modern civil calendar system used today in most of the world. It is equivalent to the proleptic Gregorian calendar system, in which today's rules for leap years are applied for all time. For most applications written today, the ISO-8601 rules are entirely suitable. However, any application that makes use of historical dates, and requires them to be accurate will find the ISO-8601 approach unsuitable.
Specification for implementors
This class is immutable and thread-safe.
Static Method Summary
Static Public Methods | ||
public static |
from(temporal: TemporalAccessor): YearMonth Obtains an instance of YearMonth from a temporal object. |
|
public static |
function overloading for YearMonth.now |
|
public static |
Obtains the current year-month from the system clock in the default time-zone. |
|
public static |
Obtains the current year-month from the specified clock. |
|
public static |
Obtains the current year-month from the system clock in the specified time-zone. |
|
public static |
function overloading for YearMonth.of |
|
public static |
ofNumberMonth(year: number, month: Month): YearMonth Obtains an instance of YearMonth from a year and month. |
|
public static |
ofNumberNumber(year: number, month: number): YearMonth Obtains an instance of YearMonth from a year and month. |
|
public static |
parse(text: String, formatter: DateTimeFormatter): YearMonth function overloading for YearMonth.parse |
|
public static |
parseString(text: String): YearMonth Obtains an instance of YearMonth from a text string such as |
|
public static |
parseStringFormatter(text: String, formatter: DateTimeFormatter): * Obtains an instance of YearMonth from a text string using a specific formatter. |
Constructor Summary
Public Constructor | ||
public |
constructor(year: number, month: number) Constructor. |
Method Summary
Public Methods | ||
public |
adjustInto(temporal: Temporal): Temporal Adjusts the specified temporal object to have this year-month. |
|
public |
Combines this year-month with a day-of-month to create a LocalDate. |
|
public |
Returns a LocalDate at the end of the month. |
|
public |
Compares this year-month to another year-month. |
|
public |
Checks if this year-month is equal to another year-month. |
|
public |
format(formatter: DateTimeFormatter): String Outputs this year-month as a string using the formatter. |
|
public |
get(field: TemporalField): number Gets the value of the specified field from this year-month as an |
|
public |
getLong(field: TemporalField): number Gets the value of the specified field from this year-month as a |
|
public |
Is this year-month after the specified year-month. |
|
public |
Is this year-month before the specified year-month. |
|
public |
Checks if the year is a leap year, according to the ISO proleptic calendar system rules. |
|
public |
isSupported(fieldOrUnit: TemporalField | ChronoUnit): boolean function overloading for YearMonth.isSupported |
|
public |
isSupportedField(field: TemporalField): boolean Checks if the specified field is supported. |
|
public |
isSupportedUnit(unit: *): * |
|
public |
isValidDay(dayOfMonth: number): boolean Checks if the day-of-month is valid for this year-month. |
|
public |
Returns the length of the month, taking account of the year. |
|
public |
Returns the length of the year. |
|
public |
minus(amountOrNumber: TemporalAmount | number, unit: TemporalUnit): YearMonth function overloading for YearMonth.minus |
|
public |
minusAmount(amount: TemporalAmount): YearMonth Returns a copy of this year-month with the specified period subtracted. |
|
public |
minusAmountUnit(amountToSubtract: number, unit: TemporalUnit): YearMonth |
|
public |
minusMonths(monthsToSubtract: number): YearMonth Returns a copy of this year-month with the specified period in months subtracted. |
|
public |
minusYears(yearsToSubtract: number): YearMonth Returns a copy of this year-month with the specified period in years subtracted. |
|
public |
Gets the month-of-year field using the Month enum. |
|
public |
monthValue(): number Gets the month-of-year field from 1 to 12. |
|
public |
plus(amountOrNumber: TemporalAmount | number, unit: TemporalUnit): YearMonth function overloading for YearMonth.plus |
|
public |
plusAmount(amount: TemporalAmount): YearMonth Returns a copy of this year-month with the specified period added. |
|
public |
plusAmountUnit(amountToAdd: number, unit: TemporalUnit): YearMonth |
|
public |
plusMonths(monthsToAdd: number): YearMonth Returns a copy of this year-month with the specified period in months added. |
|
public |
Returns a copy of this year-month with the specified period in years added. |
|
public |
query(query: TemporalQuery): * Queries this year-month using the specified query. |
|
public |
range(field: TemporalField): ValueRange Gets the range of valid values for the specified field. |
|
public |
Outputs this year-month as a string, such as |
|
public |
until(endExclusive: Temporal, unit: TemporalUnit): number Calculates the period between this year-month and another year-month in terms of the specified unit. |
|
public |
with(adjusterOrFieldOrNumber: TemporalAdjuster | TemporalField | Number, value: number): YearMonth function overloading for YearMonth.with |
|
public |
withAdjuster(adjuster: TemporalAdjuster): YearMonth Returns an adjusted copy of this year-month. |
|
public |
withFieldValue(field: TemporalField, newValue: number): * Returns a copy of this year-month with the specified field set to a new value. |
|
public |
Returns a copy of this YearMonth with the month-of-year altered. |
|
public |
Returns a copy of this YearMonth with the year altered. |
|
public |
withYearMonth(newYear: number, newMonth: number): * Returns a copy of this year-month with the new year and month, checking to see if a new object is in fact required. |
|
public |
Gets the year field. |
Inherited Summary
From class TemporalAccessor | ||
public |
get(field: TemporalField): number Gets the value of the specified field as an |
|
public |
query(query: TemporalQuery): * Queries this date-time. |
|
public |
range(field: TemporalField): ValueRange Gets the range of valid values for the specified field. |
Static Public Methods
public static from(temporal: TemporalAccessor): YearMonth source
Obtains an instance of YearMonth from a temporal object.
A TemporalAccessor represents some form of date and time information. This factory converts the arbitrary temporal object to an instance of YearMonth.
The conversion extracts the ChronoField#YEAR and ChronoField#MONTH_OF_YEAR fields. The extraction is only permitted if the temporal object has an ISO chronology, or can be converted to a LocalDate.
This method matches the signature of the functional interface TemporalQuery allowing it to be used in queries via method reference, YearMonth::from.
Params:
Name | Type | Attribute | Description |
temporal | TemporalAccessor | the temporal object to convert, not null |
Throw:
* |
DateTimeException if unable to convert to a YearMonth |
public static now(zoneIdOrClock: ZoneId | Clock): YearMonth source
function overloading for YearMonth.now
if called with 0 argument YearMonth.now0 is executed,
if called with 1 argument and first argument is an instance of ZoneId, then YearMonth.nowZoneId is executed,
otherwise YearMonth.nowClock is executed
public static now0(): YearMonth source
Obtains the current year-month from the system clock in the default time-zone.
This will query the system clock (see Clock#systemDefaultZone) in the default time-zone to obtain the current year-month. The zone and offset will be set based on the time-zone in the clock.
Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
public static nowClock(clock: Clock): YearMonth source
Obtains the current year-month from the specified clock.
This will query the specified clock to obtain the current year-month. Using this method allows the use of an alternate clock for testing. The alternate clock may be introduced using dependency injection.
Params:
Name | Type | Attribute | Description |
clock | Clock | the clock to use, not null |
public static nowZoneId(zone: ZoneId): YearMonth source
Obtains the current year-month from the system clock in the specified time-zone.
This will query the system clock (see Clock#system) to obtain the current year-month. Specifying the time-zone avoids dependence on the default time-zone.
Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
Params:
Name | Type | Attribute | Description |
zone | ZoneId | the zone ID to use, not null |
public static of(year: number, monthOrNumber: Month | number): YearMonth source
function overloading for YearMonth.of
if called with 2 argument and first argument is an instance of Month, then YearMonth.ofNumberMonth is executed,
otherwise YearMonth.ofNumberNumber is executed
public static ofNumberMonth(year: number, month: Month): YearMonth source
Obtains an instance of YearMonth from a year and month.
Throw:
* |
DateTimeException if the year value is invalid |
public static ofNumberNumber(year: number, month: number): YearMonth source
Obtains an instance of YearMonth from a year and month.
Throw:
* |
DateTimeException if either field value is invalid |
public static parse(text: String, formatter: DateTimeFormatter): YearMonth source
function overloading for YearMonth.parse
if called with 2 argument and first argument is an instance of Month, then YearMonth.parseString is executed,
otherwise YearMonth.parseStringFormatter is executed
Params:
Name | Type | Attribute | Description |
text | String |
|
|
formatter | DateTimeFormatter |
|
public static parseString(text: String): YearMonth source
Obtains an instance of YearMonth from a text string such as 2007-12
.
The string must represent a valid year-month. The format must be yyyy-MM. Years outside the range 0000 to 9999 must be prefixed by the plus or minus symbol.
Params:
Name | Type | Attribute | Description |
text | String | the text to parse such as "2007-12", not null |
Throw:
* |
DateTimeParseException if the text cannot be parsed |
public static parseStringFormatter(text: String, formatter: DateTimeFormatter): * source
Obtains an instance of YearMonth from a text string using a specific formatter.
The text is parsed using the formatter, returning a year-month.
Params:
Name | Type | Attribute | Description |
text | String | the text to parse, not null |
|
formatter | DateTimeFormatter | the formatter to use, not null |
Return:
* | the parsed year-month, not null |
Throw:
* |
DateTimeParseException if the text cannot be parsed |
Public Constructors
Public Methods
public adjustInto(temporal: Temporal): Temporal source
Adjusts the specified temporal object to have this year-month.
This returns a temporal object of the same observable type as the input with the year and month changed to be the same as this.
The adjustment is equivalent to using Temporal#with passing ChronoField#PROLEPTIC_MONTH as the field. If the specified temporal object does not use the ISO calendar system then a DateTimeException is thrown.
In most cases, it is clearer to reverse the calling pattern by using Temporal#with:
// these two lines are equivalent, but the second approach is recommended temporal = thisYearMonth.adjustInto(temporal); temporal = temporal.with(thisYearMonth);
This instance is immutable and unaffected by this method call.
Params:
Name | Type | Attribute | Description |
temporal | Temporal | the target object to be adjusted, not null |
Throw:
* |
DateTimeException if unable to make the adjustment |
* |
ArithmeticException if numeric overflow occurs |
public atDay(dayOfMonth: number): LocalDate source
Combines this year-month with a day-of-month to create a LocalDate.
This returns a LocalDate formed from this year-month and the specified day-of-month.
The day-of-month value must be valid for the year-month.
This method can be used as part of a chain to produce a date:
LocalDate date = year.atMonth(month).atDay(day);
Params:
Name | Type | Attribute | Description |
dayOfMonth | number | the day-of-month to use, from 1 to 31 |
Throw:
* |
DateTimeException if the day is invalid for the year-month |
See:
public atEndOfMonth(): LocalDate source
Returns a LocalDate at the end of the month.
This returns a LocalDate based on this year-month. The day-of-month is set to the last valid day of the month, taking into account leap years.
This method can be used as part of a chain to produce a date:
LocalDate date = year.atMonth(month).atEndOfMonth();
public compareTo(other: YearMonth): number source
Compares this year-month to another year-month.
The comparison is based first on the value of the year, then on the value of the month. It is "consistent with equals", as defined by Comparable.
Params:
Name | Type | Attribute | Description |
other | YearMonth | the other year-month to compare to, not null |
public equals(obj: *): boolean source
Checks if this year-month is equal to another year-month.
The comparison is based on the time-line position of the year-months.
Params:
Name | Type | Attribute | Description |
obj | * | the object to check, null returns false |
public format(formatter: DateTimeFormatter): String source
Outputs this year-month as a string using the formatter.
Params:
Name | Type | Attribute | Description |
formatter | DateTimeFormatter | the formatter to use, not null |
Throw:
* |
DateTimeException if an error occurs during printing |
public get(field: TemporalField): number source
Gets the value of the specified field from this year-month as an int
.
This queries this year-month for the value for the specified field. The returned value will always be within the valid range of values for the field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown.
If the field is a ChronoField then the query is implemented here.
The supported fields (see isSupported) will return valid
values based on this year-month, except EPOCH_MONTH which is too
large to fit in an int
and throw a DateTimeException.
All other ChronoField instances will throw a DateTimeException.
If the field is not a ChronoField, then the result of this method
is obtained by invoking TemporalField.getFrom
passing this
as the argument. Whether the value can be obtained,
and what the value represents, is determined by the field.
Override:
TemporalAccessor#getParams:
Name | Type | Attribute | Description |
field | TemporalField | the field to get, not null |
Throw:
* |
DateTimeException if a value for the field cannot be obtained |
* |
ArithmeticException if numeric overflow occurs |
public getLong(field: TemporalField): number source
Gets the value of the specified field from this year-month as a long
.
This queries this year-month for the value for the specified field. If it is not possible to return the value, because the field is not supported or for some other reason, an exception is thrown.
If the field is a ChronoField then the query is implemented here. The supported fields (see isSupported) will return valid values based on this year-month. All other ChronoField instances will throw a DateTimeException.
If the field is not a ChronoField, then the result of this method
is obtained by invoking TemporalField.getFrom
passing this
as the argument. Whether the value can be obtained,
and what the value represents, is determined by the field.
Params:
Name | Type | Attribute | Description |
field | TemporalField | the field to get, not null |
Throw:
* |
DateTimeException if a value for the field cannot be obtained |
* |
ArithmeticException if numeric overflow occurs |
public isAfter(other: YearMonth): boolean source
Is this year-month after the specified year-month.
Params:
Name | Type | Attribute | Description |
other | YearMonth | the other year-month to compare to, not null |
public isBefore(other: YearMonth): boolean source
Is this year-month before the specified year-month.
Params:
Name | Type | Attribute | Description |
other | YearMonth | the other year-month to compare to, not null |
public isLeapYear(): boolean source
Checks if the year is a leap year, according to the ISO proleptic calendar system rules.
This method applies the current rules for leap years across the whole time-line. In general, a year is a leap year if it is divisible by four without remainder. However, years divisible by 100, are not leap years, with the exception of years divisible by 400 which are.
For example, 1904 is a leap year it is divisible by 4. 1900 was not a leap year as it is divisible by 100, however 2000 was a leap year as it is divisible by 400.
The calculation is proleptic - applying the same rules into the far future and far past. This is historically inaccurate, but is correct for the ISO-8601 standard.
public isSupported(fieldOrUnit: TemporalField | ChronoUnit): boolean source
function overloading for YearMonth.isSupported
if called with 1 argument and first argument is an instance of TemporalField, then YearMonth.isSupportedField is executed,
otherwise YearMonth.isSupportedUnit is executed
Params:
Name | Type | Attribute | Description |
fieldOrUnit | TemporalField | ChronoUnit |
|
public isSupportedField(field: TemporalField): boolean source
Checks if the specified field is supported.
This checks if this year-month can be queried for the specified field. If false, then calling range and get will throw an exception.
If the field is a ChronoField then the query is implemented here. The supported fields (see isSupported) will return valid values based on this date-time. The supported fields are:
- MONTH_OF_YEAR
- EPOCH_MONTH
- YEAR_OF_ERA
- YEAR
- ERA
All other ChronoField instances will return false.
If the field is not a ChronoField, then the result of this method
is obtained by invoking TemporalField.isSupportedBy
passing this
as the argument.
Whether the field is supported is determined by the field.
Params:
Name | Type | Attribute | Description |
field | TemporalField | the field to check, null returns false |
public isValidDay(dayOfMonth: number): boolean source
Checks if the day-of-month is valid for this year-month.
This method checks whether this year and month and the input day form a valid date.
Params:
Name | Type | Attribute | Description |
dayOfMonth | number | the day-of-month to validate, from 1 to 31, invalid value returns false |
public lengthOfMonth(): number source
Returns the length of the month, taking account of the year.
This returns the length of the month in days. For example, a date in January would return 31.
public lengthOfYear(): number source
Returns the length of the year.
This returns the length of the year in days, either 365 or 366.
public minus(amountOrNumber: TemporalAmount | number, unit: TemporalUnit): YearMonth source
function overloading for YearMonth.minus
if called with 1 arguments, then YearMonth.minusAmount is executed.
Otherwise YearMonth.minusAmountUnit is executed.
Params:
Name | Type | Attribute | Description |
amountOrNumber | TemporalAmount | number |
|
|
unit | TemporalUnit |
|
public minusAmount(amount: TemporalAmount): YearMonth source
Returns a copy of this year-month with the specified period subtracted.
This method returns a new year-month based on this year-month with the specified period subtracted. The subtractor is typically Period but may be any other type implementing the TemporalAmount interface. The calculation is delegated to the specified adjuster, which typically calls back to minus.
This instance is immutable and unaffected by this method call.
Params:
Name | Type | Attribute | Description |
amount | TemporalAmount | the amount to subtract, not null |
Throw:
* |
DateTimeException if the subtraction cannot be made |
* |
ArithmeticException if numeric overflow occurs |
public minusAmountUnit(amountToSubtract: number, unit: TemporalUnit): YearMonth source
Params:
Name | Type | Attribute | Description |
amountToSubtract | number | the amount to subtract, not null |
|
unit | TemporalUnit |
Throw:
* |
DateTimeException if the subtraction cannot be made |
* |
ArithmeticException if numeric overflow occurs |
public minusMonths(monthsToSubtract: number): YearMonth source
Returns a copy of this year-month with the specified period in months subtracted.
This instance is immutable and unaffected by this method call.
Params:
Name | Type | Attribute | Description |
monthsToSubtract | number | the months to subtract, may be negative |
Throw:
* |
DateTimeException if the result exceeds the supported range |
public minusYears(yearsToSubtract: number): YearMonth source
Returns a copy of this year-month with the specified period in years subtracted.
This instance is immutable and unaffected by this method call.
Params:
Name | Type | Attribute | Description |
yearsToSubtract | number | the years to subtract, may be negative |
Throw:
* |
DateTimeException if the result exceeds the supported range |
public month(): Month source
Gets the month-of-year field using the Month enum.
This method returns the enum Month for the month.
This avoids confusion as to what int
values mean.
If you need access to the primitive int
value, use Month#getValue.
public monthValue(): number source
Gets the month-of-year field from 1 to 12.
This method returns the month as an int
from 1 to 12.
Application code is frequently clearer if the enum Month
is used by calling getMonth.
See:
public plus(amountOrNumber: TemporalAmount | number, unit: TemporalUnit): YearMonth source
function overloading for YearMonth.plus
if called with 1 arguments, then YearMonth.plusAmount is executed.
Otherwise YearMonth.plusAmountUnit is executed.
Params:
Name | Type | Attribute | Description |
amountOrNumber | TemporalAmount | number |
|
|
unit | TemporalUnit |
|
nullable only if first argument is an instance of TemporalAmount |
public plusAmount(amount: TemporalAmount): YearMonth source
Returns a copy of this year-month with the specified period added.
This method returns a new year-month based on this year-month with the specified period added. The adder is typically Period but may be any other type implementing the TemporalAmount interface. The calculation is delegated to the specified adjuster, which typically calls back to plus.
This instance is immutable and unaffected by this method call.
Params:
Name | Type | Attribute | Description |
amount | TemporalAmount | the amount to add, not null |
Throw:
* |
DateTimeException if the addition cannot be made |
* |
ArithmeticException if numeric overflow occurs |
public plusAmountUnit(amountToAdd: number, unit: TemporalUnit): YearMonth source
Params:
Name | Type | Attribute | Description |
amountToAdd | number | ||
unit | TemporalUnit |
Throw:
* |
DateTimeException if the addition cannot be made |
* |
ArithmeticException if numeric overflow occurs |
public plusMonths(monthsToAdd: number): YearMonth source
Returns a copy of this year-month with the specified period in months added.
This instance is immutable and unaffected by this method call.
Params:
Name | Type | Attribute | Description |
monthsToAdd | number | the months to add, may be negative |
Throw:
* |
DateTimeException if the result exceeds the supported range |
public plusYears(yearsToAdd: number): YearMonth source
Returns a copy of this year-month with the specified period in years added.
This instance is immutable and unaffected by this method call.
Params:
Name | Type | Attribute | Description |
yearsToAdd | number | the years to add, may be negative |
Throw:
* |
DateTimeException if the result exceeds the supported range |
public query(query: TemporalQuery): * source
Queries this year-month using the specified query.
This queries this year-month using the specified query strategy object. The TemporalQuery object defines the logic to be used to obtain the result. Read the documentation of the query to understand what the result of this method will be.
The result of this method is obtained by invoking the
TemporalQuery#queryFrom method on the
specified query passing this
as the argument.
Override:
TemporalAccessor#queryParams:
Name | Type | Attribute | Description |
query | TemporalQuery | the query to invoke, not null |
Return:
* | the query result, null may be returned (defined by the query) |
Throw:
* |
DateTimeException if unable to query (defined by the query) |
* |
ArithmeticException if numeric overflow occurs (defined by the query) |
public range(field: TemporalField): ValueRange source
Gets the range of valid values for the specified field.
The range object expresses the minimum and maximum valid values for a field. This year-month is used to enhance the accuracy of the returned range. If it is not possible to return the range, because the field is not supported or for some other reason, an exception is thrown.
If the field is a ChronoField then the query is implemented here. The supported fields (see isSupported) will return appropriate range instances. All other ChronoField instances will throw a DateTimeException.
If the field is not a ChronoField, then the result of this method
is obtained by invoking TemporalField.rangeRefinedBy
passing this
as the argument.
Whether the range can be obtained is determined by the field.
Override:
TemporalAccessor#rangeParams:
Name | Type | Attribute | Description |
field | TemporalField | the field to query the range for, not null |
Throw:
* |
DateTimeException if the range for the field cannot be obtained |
public toString(): String source
Outputs this year-month as a string, such as 2007-12
.
The output will be in the format yyyy-MM:
public until(endExclusive: Temporal, unit: TemporalUnit): number source
Calculates the period between this year-month and another year-month in terms of the specified unit.
This calculates the period between two year-months in terms of a single unit.
The start and end points are this
and the specified year-month.
The result will be negative if the end is before the start.
The Temporal passed to this method must be a YearMonth.
For example, the period in years between two year-months can be calculated
using startYearMonth.until.
The calculation returns a whole number, representing the number of complete units between the two year-months. For example, the period in decades between 2012-06 and 2032-05 will only be one decade as it is one month short of two decades.
This method operates in association with TemporalUnit#between.
The result of this method is a long
representing the amount of
the specified unit. By contrast, the result of between is an
object that can be used directly in addition/subtraction:
long period = start.until(end, YEARS); // this method dateTime.plus(YEARS.between(start, end)); // use in plus/minus
The calculation is implemented in this method for ChronoUnit. The units MONTHS, YEARS, DECADES, CENTURIES, MILLENNIA and ERAS are supported. Other ChronoUnit values will throw an exception.
If the unit is not a ChronoUnit, then the result of this method
is obtained by invoking TemporalUnit.between
passing this
as the first argument and the input temporal as
the second argument.
This instance is immutable and unaffected by this method call.
Params:
Name | Type | Attribute | Description |
endExclusive | Temporal | the end year-month, which is converted to a YearMonth, not null |
|
unit | TemporalUnit | the unit to measure the period in, not null |
Throw:
* |
DateTimeException if the period cannot be calculated |
* |
ArithmeticException if numeric overflow occurs |
public with(adjusterOrFieldOrNumber: TemporalAdjuster | TemporalField | Number, value: number): YearMonth source
function overloading for YearMonth.with
if called with 1 argument, then YearMonth.withAdjuster is executed,
if called with 2 arguments and first argument is an instance of TemporalField, then YearMonth.withFieldValue is executed,
otherwise YearMonth.withYearMonth is executed
Params:
Name | Type | Attribute | Description |
adjusterOrFieldOrNumber | TemporalAdjuster | TemporalField | Number |
|
|
value | number |
|
nullable only of first argument is an instance of TemporalAdjuster |
public withAdjuster(adjuster: TemporalAdjuster): YearMonth source
Returns an adjusted copy of this year-month.
This returns a new YearMonth, based on this one, with the year-month adjusted. The adjustment takes place using the specified adjuster strategy object. Read the documentation of the adjuster to understand what adjustment will be made.
A simple adjuster might simply set the one of the fields, such as the year field. A more complex adjuster might set the year-month to the next month that Halley's comet will pass the Earth.
The result of this method is obtained by invoking the
TemporalAdjuster#adjustInto method on the
specified adjuster passing this
as the argument.
This instance is immutable and unaffected by this method call.
Params:
Name | Type | Attribute | Description |
adjuster | TemporalAdjuster | the adjuster to use, not null |
Throw:
* |
DateTimeException if the adjustment cannot be made |
* |
ArithmeticException if numeric overflow occurs |
public withFieldValue(field: TemporalField, newValue: number): * source
Returns a copy of this year-month with the specified field set to a new value.
This returns a new YearMonth, based on this one, with the value for the specified field changed. This can be used to change any supported field, such as the year or month. If it is not possible to set the value, because the field is not supported or for some other reason, an exception is thrown.
If the field is a ChronoField then the adjustment is implemented here. The supported fields behave as follows:
- MONTH_OF_YEAR - Returns a YearMonth with the specified month-of-year. The year will be unchanged.
- PROLEPTIC_MONTH - Returns a YearMonth with the specified proleptic-month. This completely replaces the year and month of this object.
- YEAR_OF_ERA - Returns a YearMonth with the specified year-of-era The month and era will be unchanged.
- YEAR - Returns a YearMonth with the specified year. The month will be unchanged.
- ERA - Returns a YearMonth with the specified era. The month and year-of-era will be unchanged.
In all cases, if the new value is outside the valid range of values for the field then a DateTimeException will be thrown.
All other ChronoField instances will throw a DateTimeException.
If the field is not a ChronoField, then the result of this method
is obtained by invoking TemporalField.adjustInto
passing this
as the argument. In this case, the field determines
whether and how to adjust the instant.
This instance is immutable and unaffected by this method call.
Params:
Name | Type | Attribute | Description |
field | TemporalField | the field to set in the result, not null |
|
newValue | number | the new value of the field in the result |
Throw:
* |
DateTimeException if the field cannot be set |
* |
ArithmeticException if numeric overflow occurs |
public withMonth(month: number): YearMonth source
Returns a copy of this YearMonth with the month-of-year altered.
This instance is immutable and unaffected by this method call.
Params:
Name | Type | Attribute | Description |
month | number | the month-of-year to set in the returned year-month, from 1 (January) to 12 (December) |
Throw:
* |
DateTimeException if the month-of-year value is invalid |
public withYear(year: number): YearMonth source
Returns a copy of this YearMonth with the year altered.
This instance is immutable and unaffected by this method call.
Params:
Name | Type | Attribute | Description |
year | number | the year to set in the returned year-month, from MIN_YEAR to MAX_YEAR |
Throw:
* |
DateTimeException if the year value is invalid |