Home Reference Source
public class | source

OffsetDate

Extends:

@js-joda/core~Temporal → OffsetDate

A date with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as 2007-12-03+01:00.

OffsetDate is an immutable date-time object that represents a date, often viewed as year-month-day-offset. This object can also access other date fields such as day-of-year, day-of-week and week-of-year.

This class does not store or represent a time. For example, the value '2nd October 2007 +02:00' can be stored in an OffsetDate.

Static Method Summary

Static Public Methods
public static

Obtains an instance of OffsetDate from a temporal object.

public static

now(zoneIdOrClock: ZoneId | Clock): YearQuarter

function overloading for OffsetDate.now

public static

function overloading for OffsetDate.of

public static

ofInstant(instant: Instant, zone: ZoneId): OffsetDate

Obtains an instance of OffsetDate from an Instant and zone ID.

public static

parse(text: CharSequence, formatter: DateTimeFormatter): OffsetDate

Obtains an instance of OffsetDate from a text string using a specific formatter.

Static Protected Methods
protected static

Obtains the current date from the system clock in the default time-zone.

protected static

Obtains the current date from the specified clock.

protected static

Obtains the current date from the system clock in the specified time-zone.

protected static

_ofIntIntIntZoneOffset(year: number, month: number, dayOfMonth: number, offset: ZoneOffset): OffsetDate

Obtains an instance of OffsetDate from a year, month, day and offset.

protected static

Obtains an instance of OffsetDate from a local date and an offset.

Method Summary

Public Methods
public

Adjusts the specified temporal object to have the same offset and date as this object.

public

Returns an offset date-time formed from this date at the specified time.

public

compareTo(other: OffsetDate): number

Compares this OffsetDate to another date.

public

dayOfMonth(): number

Gets the day-of-month field.

public

Gets the day-of-week field, which is an enum DayOfWeek.

public

dayOfYear(): number

Gets the day-of-year field.

public

equals(obj: Object): boolean

Checks if this date is equal to another date.

public

format(formatter: DateTimeFormatter): string

Formats this date using the specified formatter.

public

get(field: TemporalField): number

Gets the value of the specified field from this date as an int.

public

getLong(field: TemporalField): number

Gets the value of the specified field from this date as a long.

public

hashCode(): number

A hash code for this date.

public

isAfter(other: OffsetDate): boolean

Checks if the instant of midnight at the start of this OffsetDate is after midnight at the start of the specified date.

public

isBefore(other: OffsetDate): boolean

Checks if the instant of midnight at the start of this OffsetDate is before midnight at the start of the specified date.

public

isEqual(other: OffsetDate): boolean

Checks if the instant of midnight at the start of this OffsetDate equals midnight at the start of the specified date.

public

isSupported(fieldOrUnit: TemporalField | TemporalUnit): boolean

function overloading for OffsetDate.isSupported

public

minusDays(days: number): OffsetDate

Returns a copy of this OffsetDate with the specified number of days subtracted.

public

minusMonths(months: number): OffsetDate

Returns a copy of this OffsetDate with the specified number of months subtracted.

public

minusWeeks(weeks: number): OffsetDate

Returns a copy of this OffsetDate with the specified number of weeks subtracted.

public

minusYears(years: number): OffsetDate

Returns a copy of this OffsetDate with the specified number of 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

Gets the zone offset, such as '+01:00'.

public

plusDays(days: number): OffsetDate

Returns a copy of this OffsetDate with the specified number of days added.

public

plusMonths(months: number): OffsetDate

Returns a copy of this OffsetDate with the specified number of months added.

public

plusWeeks(weeks: number): OffsetDate

Returns a copy of this OffsetDate with the specified number of weeks added.

public

plusYears(years: number): OffsetDate

Returns a copy of this OffsetDate with the specified number of years added.

public

query(query: TemporalQuery): *

Queries this date using the specified query.

public

Gets the range of valid values for the specified field.

public

toEpochSecond(time: LocalTime): number

Converts this OffsetDate to the number of seconds since the epoch of 1970-01-01T00:00:00Z.

public

Gets the LocalDate part of this date.

public

toString(): String

Outputs this date as a String, such as 2007-12-03+01:00.

public

until(endExclusive: Temporal, unit: TemporalUnit): number

Calculates the period between this date and another date in terms of the specified unit.

public

withDayOfMonth(dayOfMonth: number): OffsetDate

Returns a copy of this OffsetDate with the day-of-month altered.

public

withDayOfYear(dayOfYear: number): OffsetDate

Returns a copy of this OffsetDate with the day-of-year altered.

public

withMonth(month: number): OffsetDate

Returns a copy of this OffsetDate with the month-of-year altered.

public

Returns a copy of this OffsetDate with the specified offset ensuring that the result has the same local date.

public

withYear(year: OffsetDate): number

Returns a copy of this OffsetDate with the year altered.

public

year(): number

Gets the year field.

Protected Methods
protected

_isSupportedField(field: TemporalField): boolean

Checks if the specified field is supported.

protected

_isSupportedUnit(unit: TemporalUnit): boolean

Checks if the specified unit is supported.

Static Public Methods

public static from(temporal: TemporalAccessor): OffsetDate source

Obtains an instance of OffsetDate 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 OffsetDate.

The conversion extracts and combines LocalDate and ZoneOffset.

This method matches the signature of the functional interface TemporalQuery allowing it to be used in queries via method reference, OffsetDate.FROM.

Params:

NameTypeAttributeDescription
temporal TemporalAccessor

the temporal object to convert, not null

Return:

OffsetDate

the offset date, not null

Throw:

DateTimeException

if unable to convert to an OffsetDate

public static now(zoneIdOrClock: ZoneId | Clock): YearQuarter source

function overloading for OffsetDate.now

Params:

NameTypeAttributeDescription
zoneIdOrClock ZoneId | Clock
  • nullable: true

Return:

YearQuarter

public static of(): YearQuarter source

function overloading for OffsetDate.of

Return:

YearQuarter

public static ofInstant(instant: Instant, zone: ZoneId): OffsetDate source

Obtains an instance of OffsetDate from an Instant and zone ID.

This creates an offset date with the same instant as midnight at the start of day of the instant specified. Finding the offset from UTC/Greenwich is simple as there is only one valid offset for each instant.

Params:

NameTypeAttributeDescription
instant Instant

the instant to create the time from, not null

zone ZoneId

the time-zone, which may be an offset, not null

Return:

OffsetDate

the offset time, not null

public static parse(text: CharSequence, formatter: DateTimeFormatter): OffsetDate source

Obtains an instance of OffsetDate from a text string using a specific formatter.

The text is parsed using the formatter, returning a date.

Params:

NameTypeAttributeDescription
text CharSequence

the text to parse, not null

formatter DateTimeFormatter

the formatter to use, not null

Return:

OffsetDate

the parsed offset date, not null

Throw:

DateTimeParseException

if the text cannot be parsed

Static Protected Methods

protected static _now0(): OffsetDate source

Obtains the current date from the system clock in the default time-zone.

This will query the Clock.systemDefaultZone system clock in the default time-zone to obtain the current date. The offset will be calculated from 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.

Return:

OffsetDate

the current date using the system clock, not null

protected static _nowClock(clock: Clock): OffsetDate source

Obtains the current date from the specified clock.

This will query the specified clock to obtain the current date - today. The offset will be calculated from the time-zone in the clock.

Using this method allows the use of an alternate clock for testing. The alternate clock may be introduced using Clock dependency injection.

Params:

NameTypeAttributeDescription
clock Clock

the clock to use, not null

Return:

OffsetDate

the current date, not null

protected static _nowZoneId(zone: ZoneId): OffsetDate source

Obtains the current date from the system clock in the specified time-zone.

This will query the Clock.system system clock to obtain the current date. Specifying the time-zone avoids dependence on the default time-zone. The offset will be calculated from the specified time-zone.

Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.

Params:

NameTypeAttributeDescription
zone ZoneId

the zone ID to use, not null

Return:

OffsetDate

the current date using the system clock, not null

protected static _ofIntIntIntZoneOffset(year: number, month: number, dayOfMonth: number, offset: ZoneOffset): OffsetDate source

Obtains an instance of OffsetDate from a year, month, day and offset.

This creates an offset date with the four specified fields.

This method exists primarily for writing test cases. Non test-code will typically use other methods to create an offset time.

Params:

NameTypeAttributeDescription
year number

the year to represent, from MIN_YEAR to MAX_YEAR

month number

the month-of-year to represent, from 1 (January) to 12 (December)

dayOfMonth number

the day-of-month to represent, from 1 to 31

offset ZoneOffset

the zone offset, not null

Return:

OffsetDate

the offset date, not null

Throw:

DateTimeException

if the value of any field is out of range, or if the day-of-month is invalid for the month-year

protected static _ofLocalDateZoneOffset(date: LocalDate, offset: ZoneOffset): OffsetDate source

Obtains an instance of OffsetDate from a local date and an offset.

Params:

NameTypeAttributeDescription
date LocalDate

the local date, not null

offset ZoneOffset

the zone offset, not null

Return:

OffsetDate

the offset date, not null

Public Methods

public adjustInto(temporal: Temporal): Temporal source

Adjusts the specified temporal object to have the same offset and date as this object.

This returns a temporal object of the same observable type as the input with the offset and date changed to be the same as this.

The adjustment is equivalent to using Temporal.with twice, passing ChronoField.OFFSET_SECONDS and ChronoField.EPOCH_DAY as the fields.

In most cases, it is clearer to reverse the calling pattern by using {@link Temporal.with(TemporalAdjuster)}:

  // these two lines are equivalent, but the second approach is recommended
  temporal = thisOffsetDate.adjustInto(temporal);
  temporal = temporal.with(thisOffsetDate);

This instance is immutable and unaffected by this method call.

Params:

NameTypeAttributeDescription
temporal Temporal

the target object to be adjusted, not null

Return:

Temporal

the adjusted object, not null

Throw:

DateTimeException

if unable to make the adjustment

ArithmeticException

if numeric overflow occurs

public atTime(time: LocalTime): OffsetDateTime source

Returns an offset date-time formed from this date at the specified time.

This combines this date with the specified time to form an OffsetDateTime. All possible combinations of date and time are valid.

This instance is immutable and unaffected by this method call.

Params:

NameTypeAttributeDescription
time LocalTime

the time to combine with, not null

Return:

OffsetDateTime

the offset date-time formed from this date and the specified time, not null

public compareTo(other: OffsetDate): number source

Compares this OffsetDate to another date.

The comparison is based first on the UTC equivalent instant, then on the local date. It is 'consistent with equals', as defined by Comparable.

For example, the following is the comparator order:

  1. 2008-06-29-11:00
  2. 2008-06-29-12:00
  3. 2008-06-30+12:00
  4. 2008-06-29-13:00

Values #2 and #3 represent the same instant on the time-line. When two values represent the same instant, the local date is compared to distinguish them. This step is needed to make the ordering consistent with equals().

To compare the underlying local date of two TemporalAccessor instances, use ChronoField.EPOCH_DAY as a comparator.

Params:

NameTypeAttributeDescription
other OffsetDate

the other date to compare to, not null

Return:

number

the comparator value, negative if less, positive if greater

public dayOfMonth(): number source

Gets the day-of-month field.

This method returns the primitive int value for the day-of-month.

Return:

number

the day-of-month, from 1 to 31

public dayOfWeek(): DayOfWeek source

Gets the day-of-week field, which is an enum DayOfWeek.

This method returns the enum DayOfWeek for the day-of-week. This avoids confusion as to what int values mean. If you need access to the primitive int value then the enum provides the DayOfWeek.value int value.

Additional information can be obtained from the DayOfWeek. This includes textual names of the values.

Return:

DayOfWeek

the day-of-week, not null

public dayOfYear(): number source

Gets the day-of-year field.

This method returns the primitive int value for the day-of-year.

Return:

number

the day-of-year, from 1 to 365, or 366 in a leap year

public equals(obj: Object): boolean source

Checks if this date is equal to another date.

The comparison is based on the local-date and the offset. To compare for the same instant on the time-line, use OffsetDate.isEqual.

Only objects of type OffsetDate are compared, other types return false. To compare the underlying local date of two TemporalAccessor instances, use ChronoField.EPOCH_DAY as a comparator.

Params:

NameTypeAttributeDescription
obj Object

the object to check, null returns false

Return:

boolean

true if this is equal to the other date

public format(formatter: DateTimeFormatter): string source

Formats this date using the specified formatter.

This date will be passed to the formatter to produce a string.

Params:

NameTypeAttributeDescription
formatter DateTimeFormatter

the formatter to use, not null

Return:

string

the formatted date string, 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 date as an int.

This queries this date 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 OffsetDate.isSupported supported fields will return valid values based on this date, except EPOCH_DAY and PROLEPTIC_MONTH which are 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(TemporalAccessor) passing this as the argument. Whether the value can be obtained, and what the value represents, is determined by the field.

Params:

NameTypeAttributeDescription
field TemporalField

the field to get, not null

Return:

number

the value for the field

Throw:

DateTimeException

if a value for the field cannot be obtained or the value is outside the range of valid values for the field

UnsupportedTemporalTypeException

if the field is not supported or the range of values exceeds an int

ArithmeticException

if numeric overflow occurs

public getLong(field: TemporalField): number source

Gets the value of the specified field from this date as a long.

This queries this date 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 OffsetDate.isSupported supported fields will return valid values based on this date. All other ChronoField instances will throw an UnsupportedTemporalTypeException.

If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.getFrom(TemporalAccessor) passing this as the argument. Whether the value can be obtained, and what the value represents, is determined by the field.

Params:

NameTypeAttributeDescription
field TemporalField

the field to get, not null

Return:

number

the value for the field

Throw:

DateTimeException

if a value for the field cannot be obtained

UnsupportedTemporalTypeException

if the field is not supported

ArithmeticException

if numeric overflow occurs

public hashCode(): number source

A hash code for this date.

Return:

number

a suitable hash code

public isAfter(other: OffsetDate): boolean source

Checks if the instant of midnight at the start of this OffsetDate is after midnight at the start of the specified date.

This method differs from the comparison in OffsetDate.compareTo in that it only compares the instant of the date. This is equivalent to using date1.toEpochSecond().isAfter(date2.toEpochSecond()).

Params:

NameTypeAttributeDescription
other OffsetDate

the other date to compare to, not null

Return:

boolean

true if this is after the instant of the specified date

public isBefore(other: OffsetDate): boolean source

Checks if the instant of midnight at the start of this OffsetDate is before midnight at the start of the specified date.

This method differs from the comparison in OffsetDate.compareTo in that it only compares the instant of the date. This is equivalent to using date1.toEpochSecond().isBefore(date2.toEpochSecond()).

Params:

NameTypeAttributeDescription
other OffsetDate

the other date to compare to, not null

Return:

boolean

true if this is before the instant of the specified date

public isEqual(other: OffsetDate): boolean source

Checks if the instant of midnight at the start of this OffsetDate equals midnight at the start of the specified date.

This method differs from the comparison in OffsetDate.compareTo and OffsetDate.equals in that it only compares the instant of the date. This is equivalent to using date1.toEpochSecond().equals(date2.toEpochSecond()).

Params:

NameTypeAttributeDescription
other OffsetDate

the other date to compare to, not null

Return:

boolean

true if the instant equals the instant of the specified date

public isSupported(fieldOrUnit: TemporalField | TemporalUnit): boolean source

function overloading for OffsetDate.isSupported

Params:

NameTypeAttributeDescription
fieldOrUnit TemporalField | TemporalUnit

Return:

boolean

public minusDays(days: number): OffsetDate source

Returns a copy of this OffsetDate with the specified number of days subtracted.

This uses LocalDate.minusDays to subtract the days. The offset does not affect the calculation and will be the same in the result.

This instance is immutable and unaffected by this method call.

Params:

NameTypeAttributeDescription
days number

the days to subtract, may be negative

Return:

OffsetDate

an OffsetDate based on this date with the days subtracted, not null

Throw:

DateTimeException

if the result exceeds the supported date range

public minusMonths(months: number): OffsetDate source

Returns a copy of this OffsetDate with the specified number of months subtracted.

This uses LocalDate.minusMonths to subtract the months. The offset does not affect the calculation and will be the same in the result.

This instance is immutable and unaffected by this method call.

Params:

NameTypeAttributeDescription
months number

the months to subtract, may be negative

Return:

OffsetDate

an OffsetDate based on this date with the months subtracted, not null

Throw:

DateTimeException

if the result exceeds the supported date range

public minusWeeks(weeks: number): OffsetDate source

Returns a copy of this OffsetDate with the specified number of weeks subtracted.

This uses LocalDate.minusWeeks to subtract the weeks. The offset does not affect the calculation and will be the same in the result.

This instance is immutable and unaffected by this method call.

Params:

NameTypeAttributeDescription
weeks number

the weeks to subtract, may be negative

Return:

OffsetDate

an OffsetDate based on this date with the weeks subtracted, not null

Throw:

DateTimeException

if the result exceeds the supported date range

public minusYears(years: number): OffsetDate source

Returns a copy of this OffsetDate with the specified number of years subtracted.

This uses LocalDate.minusYears to subtract the years. The offset does not affect the calculation and will be the same in the result.

This instance is immutable and unaffected by this method call.

Params:

NameTypeAttributeDescription
years number

the years to subtract, may be negative

Return:

OffsetDate

an OffsetDate based on this date with the years subtracted, not null

Throw:

DateTimeException

if the result exceeds the supported date 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 then the enum provides the Month.value int value.

Return:

Month

the month-of-year, not null

See:

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 OffsetDate.month.

Return:

number

the month-of-year, from 1 to 12

See:

public offset(): ZoneOffset source

Gets the zone offset, such as '+01:00'.

This is the offset of the local date from UTC/Greenwich.

Return:

ZoneOffset

the zone offset, not null

public plusDays(days: number): OffsetDate source

Returns a copy of this OffsetDate with the specified number of days added.

This uses {@link LocalDate.plusDays)} to add the days. The offset does not affect the calculation and will be the same in the result.

This instance is immutable and unaffected by this method call.

Params:

NameTypeAttributeDescription
days number

the days to add, may be negative

Return:

OffsetDate

an OffsetDate based on this date with the days added, not null

Throw:

DateTimeException

if the result exceeds the supported date range

public plusMonths(months: number): OffsetDate source

Returns a copy of this OffsetDate with the specified number of months added.

This uses LocalDate.plusMonths to add the months. The offset does not affect the calculation and will be the same in the result.

This instance is immutable and unaffected by this method call.

Params:

NameTypeAttributeDescription
months number

the months to add, may be negative

Return:

OffsetDate

an OffsetDate based on this date with the months added, not null

Throw:

DateTimeException

if the result exceeds the supported date range

public plusWeeks(weeks: number): OffsetDate source

Returns a copy of this OffsetDate with the specified number of weeks added.

This uses LocalDate.plusWeeks to add the weeks. The offset does not affect the calculation and will be the same in the result.

This instance is immutable and unaffected by this method call.

Params:

NameTypeAttributeDescription
weeks number

the weeks to add, may be negative

Return:

OffsetDate

an OffsetDate based on this date with the weeks added, not null

Throw:

DateTimeException

if the result exceeds the supported date range

public plusYears(years: number): OffsetDate source

Returns a copy of this OffsetDate with the specified number of years added.

This uses LocalDate.plusYears to add the years. The offset does not affect the calculation and will be the same in the result.

This instance is immutable and unaffected by this method call.

Params:

NameTypeAttributeDescription
years number

the years to add, may be negative

Return:

OffsetDate

an OffsetDate based on this date with the years added, not null

Throw:

DateTimeException

if the result exceeds the supported date range

public query(query: TemporalQuery): * source

Queries this date using the specified query.

This queries this date 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.

Params:

NameTypeAttributeDescription
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 date 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 OffsetDate.isSupported supported fields will return appropriate range instances. All other ChronoField instances will throw an UnsupportedTemporalTypeException.

If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.rangeRefinedBy(TemporalAccessor) passing this as the argument. Whether the range can be obtained is determined by the field.

Params:

NameTypeAttributeDescription
field TemporalField

the field to query the range for, not null

Return:

ValueRange

the range of valid values for the field, not null

Throw:

DateTimeException

if the range for the field cannot be obtained

UnsupportedTemporalTypeException

if the field is not supported

public toEpochSecond(time: LocalTime): number source

Converts this OffsetDate to the number of seconds since the epoch of 1970-01-01T00:00:00Z.

This combines this offset date with the specified time to calculate the epoch-second value, which is the number of elapsed seconds from 1970-01-01T00:00:00Z. Instants on the time-line after the epoch are positive, earlier are negative.

Params:

NameTypeAttributeDescription
time LocalTime

the local time, not null

Return:

number

the number of seconds since the epoch of 1970-01-01T00:00:00Z, may be negative

public toLocalDate(): LocalDate source

Gets the LocalDate part of this date.

This returns a LocalDate with the same year, month and day as this date.

Return:

LocalDate

the date part of this date, not null

public toString(): String source

Outputs this date as a String, such as 2007-12-03+01:00.

The output will be in the ISO-8601 format yyyy-MM-ddXXXXX.

Return:

String

a string representation of this date, not null

public until(endExclusive: Temporal, unit: TemporalUnit): number source

Calculates the period between this date and another date in terms of the specified unit.

This calculates the period between two dates in terms of a single unit. The start and end points are this and the specified date. The result will be negative if the end is before the start. For example, the period in days between two dates can be calculated using startDate.until(endDate, DAYS).

The Temporal passed to this method is converted to a OffsetDate using OffsetDate.from. If the offset differs between the two times, then the specified end time is normalized to have the same offset as this time.

The calculation returns a whole number, representing the number of complete units between the two dates. For example, the period in months between 2012-06-15Z and 2012-08-14Z will only be one month as it is one day short of two months.

There are two equivalent ways of using this method. The first is to invoke this method. The second is to use TemporalUnit.between:

  // these two lines are equivalent
  amount = start.until(end, DAYS);
  amount = DAYS.between(start, end);
The choice should be made based on which makes the code more readable.

The calculation is implemented in this method for ChronoUnit. The units DAYS, WEEKS, 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(Temporal, Temporal) passing this as the first argument and the converted input temporal as the second argument.

This instance is immutable and unaffected by this method call.

Params:

NameTypeAttributeDescription
endExclusive Temporal

the end time, exclusive, which is converted to an OffsetDate, not null

unit TemporalUnit

the unit to measure the amount in, not null

Return:

number

the amount of time between this date and the end date

Throw:

DateTimeException

if the amount cannot be calculated, or the end temporal cannot be converted to an OffsetDate

UnsupportedTemporalTypeException

if the unit is not supported

ArithmeticException

if numeric overflow occurs

public withDayOfMonth(dayOfMonth: number): OffsetDate source

Returns a copy of this OffsetDate with the day-of-month altered.

If the resulting date is invalid, an exception is thrown. The offset does not affect the calculation and will be the same in the result.

This instance is immutable and unaffected by this method call.

Params:

NameTypeAttributeDescription
dayOfMonth number

the day-of-month to set in the result, from 1 to 28-31

Return:

OffsetDate

an OffsetDate based on this date with the requested day, not null

Throw:

DateTimeException

if the day-of-month value is invalid, or if the day-of-month is invalid for the month-year

public withDayOfYear(dayOfYear: number): OffsetDate source

Returns a copy of this OffsetDate with the day-of-year altered.

If the resulting date is invalid, an exception is thrown.

This instance is immutable and unaffected by this method call.

Params:

NameTypeAttributeDescription
dayOfYear number

the day-of-year to set in the result, from 1 to 365-366

Return:

OffsetDate

an OffsetDate based on this date with the requested day, not null

Throw:

DateTimeException

if the day-of-year value is invalid, or if the day-of-year is invalid for the year

public withMonth(month: number): OffsetDate source

Returns a copy of this OffsetDate with the month-of-year altered.

The offset does not affect the calculation and will be the same in the result. If the day-of-month is invalid for the year, it will be changed to the last valid day of the month.

This instance is immutable and unaffected by this method call.

Params:

NameTypeAttributeDescription
month number

the month-of-year to set in the result, from 1 (January) to 12 (December)

Return:

OffsetDate

an OffsetDate based on this date with the requested month, not null

Throw:

DateTimeException

if the month-of-year value is invalid

public withOffsetSameLocal(offset: ZoneOffset): OffsetDate source

Returns a copy of this OffsetDate with the specified offset ensuring that the result has the same local date.

This method returns an object with the same LocalDate and the specified ZoneOffset. No calculation is needed or performed. For example, if this time represents 2007-12-03+02:00 and the offset specified is +03:00, then this method will return 2007-12-03+03:00.

This instance is immutable and unaffected by this method call.

Params:

NameTypeAttributeDescription
offset ZoneOffset

the zone offset to change to, not null

Return:

OffsetDate

an OffsetDate based on this date with the requested offset, not null

public withYear(year: OffsetDate): number source

Returns a copy of this OffsetDate with the year altered.

The offset does not affect the calculation and will be the same in the result. If the day-of-month is invalid for the year, it will be changed to the last valid day of the month.

This instance is immutable and unaffected by this method call.

Params:

NameTypeAttributeDescription
year OffsetDate

the year to set in the result, from MIN_YEAR to MAX_YEAR

Return:

number

an OffsetDate based on this date with the requested year, not null

Throw:

DateTimeException

if the year value is invalid

public year(): number source

Gets the year field.

This method returns the primitive int value for the year.

The year returned by this method is proleptic as per get(YEAR). To obtain the year-of-era, use get(YEAR_OF_ERA).

Return:

number

the year, from MIN_YEAR to MAX_YEAR

Protected Methods

protected _isSupportedField(field: TemporalField): boolean source

Checks if the specified field is supported.

This checks if this date can be queried for the specified field. If false, then calling the OffsetDate.range, OffsetDate.get and OffsetDate.with methods will throw an exception.

If the field is a ChronoField then the query is implemented here. The supported fields are:

  • DAY_OF_WEEK
  • ALIGNED_DAY_OF_WEEK_IN_MONTH
  • ALIGNED_DAY_OF_WEEK_IN_YEAR
  • DAY_OF_MONTH
  • DAY_OF_YEAR
  • EPOCH_DAY
  • ALIGNED_WEEK_OF_MONTH
  • ALIGNED_WEEK_OF_YEAR
  • MONTH_OF_YEAR
  • PROLEPTIC_MONTH
  • YEAR_OF_ERA
  • YEAR
  • ERA
  • OFFSET_SECONDS

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(TemporalAccessor) passing this as the argument. Whether the field is supported is determined by the field.

Params:

NameTypeAttributeDescription
field TemporalField

the field to check, null returns false

Return:

boolean

true if the field is supported on this date, false if not

protected _isSupportedUnit(unit: TemporalUnit): boolean source

Checks if the specified unit is supported.

This checks if the specified unit can be added to, or subtracted from, this date. If false, then calling the {@link OffsetDate.plus(long, TemporalUnit)} and {@link OffsetDate.minus(long, TemporalUnit) minus} methods will throw an exception.

If the unit is a ChronoUnit then the query is implemented here. The supported units are:

    • DAYS
    • WEEKS
    • MONTHS
    • YEARS
    • DECADES
    • CENTURIES
    • MILLENNIA
    • ERAS
    All other ChronoUnit instances will return false.

    If the unit is not a ChronoUnit, then the result of this method is obtained by invoking TemporalUnit.isSupportedBy(Temporal) passing this as the argument. Whether the unit is supported is determined by the unit.

    Params:

    NameTypeAttributeDescription
    unit TemporalUnit

    the unit to check, null returns false

    Return:

    boolean

    true if the unit can be added/subtracted, false if not