import {OffsetDateTime} from '@js-joda/root/packages/core/src/OffsetDateTime.js'
OffsetDateTime
Extends:
A date-time with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as 2007-12-23T10:15:30+01:00.
Static Method Summary
Static Public Methods | ||
public static |
from(temporal: TemporaroAccessor): OffsetDateTime |
|
public static |
now(clockOrZone: Clock | ZoneId | null): OffsetDateTime |
|
public static |
of(): OffsetDateTime |
|
public static |
ofDateAndTime(date: *, time: *, offset: *): * |
|
public static |
ofDateTime(dateTime: *, offset: *): * |
|
public static |
ofInstant(instant: Instant, zone: ZoneId): OffsetDateTime |
|
public static |
ofNumbers(year: *, month: *, dayOfMonth: *, hour: number, minute: number, second: number, nanoOfSecond: number, offset: *): * |
|
public static |
parse(text: string, formatter: DateTimeFormatter | undefined): OffsetTime |
Method Summary
Public Methods | ||
public |
adjustInto(temporal: Temporal): Temporal |
|
public |
atZoneSameInstant(zone: ZoneId): ZonedDateTime |
|
public |
atZoneSimilarLocal(zone: ZoneId): ZonedDateTime |
|
public |
compareTo(other: *): * |
|
public |
dayOfMonth(): number |
|
public |
dayOfWeek(): number |
|
public |
dayOfYear(): number |
|
public |
equals(other: *): boolean |
|
public |
format(formatter: DateTimeFormatter): string |
|
public |
get(field: *): * |
|
public |
getLong(field: *): * |
|
public |
hashCode(): number |
|
public |
hour(): number |
|
public |
isAfter(other: OffsetDateTime): boolean |
|
public |
isBefore(other: OffsetDateTime): boolean |
|
public |
isEqual(other: OffsetDateTime): boolean |
|
public |
isSupported(fieldOrUnit: *): * |
|
public |
minusDays(days: int): OffsetTime |
|
public |
minusHours(hours: int): OffsetTime |
|
public |
minusMinutes(minutes: int): OffsetTime |
|
public |
minusMonths(months: int): OffsetTime |
|
public |
minusNanos(nanos: int): OffsetTime |
|
public |
minusSeconds(seconds: int): OffsetTime |
|
public |
minusWeeks(weeks: int): OffsetTime |
|
public |
minusYears(years: int): OffsetTime |
|
public |
minute(): number |
|
public |
month(): {number |
|
public |
monthValue(): number |
|
public |
nano(): number |
|
public |
offset(): ZoneOffset |
|
public |
plusDays(days: int): OffsetTime |
|
public |
plusHours(hours: int): OffsetTime |
|
public |
plusMinutes(minutes: int): OffsetTime |
|
public |
plusMonths(months: int): OffsetTime |
|
public |
plusNanos(nanos: int): OffsetTime |
|
public |
plusSeconds(seconds: int): OffsetTime |
|
public |
plusWeeks(weeks: int): OffsetTime |
|
public |
plusYears(years: int): OffsetTime |
|
public |
query(query: *): * |
|
public |
range(field: *): * |
|
public |
second(): number |
|
public |
toEpochSecond(): number |
|
public |
|
|
public |
toJSON(): string |
|
public |
|
|
public |
toLocalDateTime(): * |
|
public |
|
|
public |
|
|
public |
toString(): * |
|
public |
toZonedDateTime(): * |
|
public |
truncatedTo(unit: TemporalUnit): OffsetDateTime |
|
public |
until(endExclusive: *, unit: *): * |
|
public |
withDayOfMonth(dayOfMonth: int): OffsetDateTime |
|
public |
withDayOfYear(dayOfYear: int): OffsetDateTime |
|
public |
withHour(hour: int): OffsetDateTime |
|
public |
withMinute(minute: int): OffsetDateTime |
|
public |
withMonth(month: int): OffsetDateTime |
|
public |
withNano(nanoOfSecond: int): OffsetDateTime |
|
public |
withOffsetSameInstant(offset: ZoneOffset): OffsetDateTime |
|
public |
withOffsetSameLocal(offset: ZoneOffset): OffsetDateTime |
|
public |
withSecond(second: int): OffsetDateTime |
|
public |
withYear(year: int): OffsetDateTime |
|
public |
year(): number |
Inherited Summary
From class TemporalAccessor | ||
public |
get(field: TemporalField): number Gets the value of the specified field as an |
|
public |
getLong(field: *) |
|
public |
isSupported(field: *) |
|
public |
query(query: TemporalQuery): * Queries this date-time. |
|
public |
range(field: TemporalField): ValueRange Gets the range of valid values for the specified field. |
From class Temporal | ||
public |
isSupported(fieldOrUnit: TemporalUnit): boolean Checks if the specified unit is supported. |
|
public |
minus(amount: TemporalAmount | number, unit: TemporalUnit): Temporal function overloading for Temporal.plus |
|
public |
plus(amount: TemporalAmount | number, unit: TemporalUnit): Temporal function overloading for Temporal.plus |
|
public |
until(endTemporal: Temporal, unit: TemporalUnit): number Calculates the period between this temporal and another temporal in terms of the specified unit. |
|
public |
with(adjusterOrField: TemporalAdjuster | TemporalField, newValue: number): Temporal function overloading for Temporal.with |
Static Public Methods
public static from(temporal: TemporaroAccessor): OffsetDateTime source
Params:
Name | Type | Attribute | Description |
temporal | TemporaroAccessor |
public static now(clockOrZone: Clock | ZoneId | null): OffsetDateTime source
public static ofDateAndTime(date: *, time: *, offset: *): * source
Params:
Name | Type | Attribute | Description |
date | * | ||
time | * | ||
offset | * |
Return:
* |
public static ofDateTime(dateTime: *, offset: *): * source
Params:
Name | Type | Attribute | Description |
dateTime | * | ||
offset | * |
Return:
* |
public static ofInstant(instant: Instant, zone: ZoneId): OffsetDateTime source
public static ofNumbers(year: *, month: *, dayOfMonth: *, hour: number, minute: number, second: number, nanoOfSecond: number, offset: *): * source
Params:
Name | Type | Attribute | Description |
year | * | ||
month | * | ||
dayOfMonth | * | ||
hour | number |
|
|
minute | number |
|
|
second | number |
|
|
nanoOfSecond | number |
|
|
offset | * |
Return:
* |
public static parse(text: string, formatter: DateTimeFormatter | undefined): OffsetTime source
Params:
Name | Type | Attribute | Description |
text | string | ||
formatter | DateTimeFormatter | undefined |
Public Methods
public adjustInto(temporal: Temporal): Temporal source
Params:
Name | Type | Attribute | Description |
temporal | Temporal |
public atZoneSameInstant(zone: ZoneId): ZonedDateTime source
Params:
Name | Type | Attribute | Description |
zone | ZoneId |
public atZoneSimilarLocal(zone: ZoneId): ZonedDateTime source
Params:
Name | Type | Attribute | Description |
zone | ZoneId |
public dayOfYear(): number source
Return:
number | the day-of-year, from 1 to 365, or 366 in a leap year |
public equals(other: *): boolean source
Params:
Name | Type | Attribute | Description |
other | * |
Return:
boolean |
public format(formatter: DateTimeFormatter): string source
Params:
Name | Type | Attribute | Description |
formatter | DateTimeFormatter |
Return:
string |
public get(field: *): * source
Gets the value of the specified field as an int
.
This queries the date-time for the value for the specified field. The returned value will always be within the valid range of values for the field. If the date-time cannot return the value, because the field is unsupported or for some other reason, an exception will be thrown.
Specification for implementors
Implementations must check and handle all fields defined in ChronoField.
If the field is supported and has an int
range, then the value of
the field must be returned.
If unsupported, then a DateTimeException must be thrown.
If the field is not a ChronoField, then the result of this method
is obtained by invoking TemporalField.getFrom
passing this
as the argument.
Implementations must not alter either this object.
Override:
TemporalAccessor#getParams:
Name | Type | Attribute | Description |
field | * |
Return:
* |
public getLong(field: *): * source
Override:
TemporalAccessor#getLongParams:
Name | Type | Attribute | Description |
field | * |
Return:
* |
public isAfter(other: OffsetDateTime): boolean source
Params:
Name | Type | Attribute | Description |
other | OffsetDateTime |
Return:
boolean |
public isBefore(other: OffsetDateTime): boolean source
Params:
Name | Type | Attribute | Description |
other | OffsetDateTime |
Return:
boolean |
public isEqual(other: OffsetDateTime): boolean source
Params:
Name | Type | Attribute | Description |
other | OffsetDateTime |
Return:
boolean |
public isSupported(fieldOrUnit: *): * source
Checks if the specified unit is supported. This checks if the date-time can be queried for the specified unit. If false, then calling the plus and minus methods will throw an exception.
Specification for implementors
Implementations must check and handle all fields defined in ChronoUnit. If the field is supported, then true is returned, otherwise false
If the field is not a ChronoUnit, then the result of this method is obtained by invoking TemporalUnit.isSupportedBy(Temporal)
passing this as the argument.
Implementations must not alter this object.
Override:
Temporal#isSupportedParams:
Name | Type | Attribute | Description |
fieldOrUnit | * |
Return:
* |
public minusDays(days: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
days | int |
public minusHours(hours: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
hours | int |
public minusMinutes(minutes: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
minutes | int |
public minusMonths(months: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
months | int |
public minusNanos(nanos: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
nanos | int |
public minusSeconds(seconds: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
seconds | int |
public minusWeeks(weeks: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
weeks | int |
public minusYears(years: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
years | int |
public plusDays(days: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
days | int |
public plusHours(hours: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
hours | int |
public plusMinutes(minutes: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
minutes | int |
public plusMonths(months: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
months | int |
public plusNanos(nanos: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
nanos | int |
public plusSeconds(seconds: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
seconds | int |
public plusWeeks(weeks: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
weeks | int |
public plusYears(years: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
years | int |
public query(query: *): * source
Queries this date-time.
This queries this date-time using the specified query strategy object.
Queries are a key tool for extracting information from date-times. They exists to externalize the process of querying, permitting different approaches, as per the strategy design pattern. Examples might be a query that checks if the date is the day before February 29th in a leap year, or calculates the number of days to your next birthday.
The most common query implementations are method references, such as LocalDate::from and ZoneId::from. Further implementations are on TemporalQueries. Queries may also be defined by applications.
Override:
TemporalAccessor#queryParams:
Name | Type | Attribute | Description |
query | * |
Return:
* |
public range(field: *): * source
Gets the range of valid values for the specified field.
All fields can be expressed as a long
integer.
This method returns an object that describes the valid range for that value.
The value of this temporal object is used to enhance the accuracy of the returned range.
If the date-time cannot return the range, because the field is unsupported or for
some other reason, an exception will be thrown.
Note that the result only describes the minimum and maximum valid values and it is important not to read too much into them. For example, there could be values within the range that are invalid for the field.
Specification for implementors
Implementations must check and handle all fields defined in ChronoField. If the field is supported, then the range of the field must be returned. If unsupported, then a DateTimeException must be thrown.
If the field is not a ChronoField, then the result of this method
is obtained by invoking TemporalField.rangeRefinedBy
passing this
as the argument.
Implementations must not alter either this object.
Override:
TemporalAccessor#rangeParams:
Name | Type | Attribute | Description |
field | * |
Return:
* |
public toEpochSecond(): number source
Return:
number | the number of seconds from the epoch of 1970-01-01T00:00:00Z |
public toLocalDateTime(): * source
Return:
* | {LocalDateTime}the local date-time part of this date-time, not null |
public toOffsetTime(): OffsetTime source
public toZonedDateTime(): * source
Return:
* | {ZonedDateTime}a zoned date-time representing the same local date-time and offset, not null |
public truncatedTo(unit: TemporalUnit): OffsetDateTime source
Params:
Name | Type | Attribute | Description |
unit | TemporalUnit |
public until(endExclusive: *, unit: *): * source
Calculates the period between this temporal and another temporal in terms of the specified unit.
This calculates the period between two temporals in terms of a single unit. The start and end points are this and the specified temporal. The result will be negative if the end is before the start. For example, the period in hours between two temporal objects can be calculated using startTime.until(endTime, HOURS)
.
The calculation returns a whole number, representing the number of complete units between the two temporals. For example, the period in hours between the times 11:30 and 13:29 will only be one hour as it is one minute short of two hours.
There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use TemporalUnit.between(Temporal, Temporal)
:
// these two lines are equivalent between = thisUnit.between(start, end); between = start.until(end, thisUnit);
The choice should be made based on which makes the code more readable. For example, this method allows the number of days between two dates to be calculated:
long daysBetween = DAYS.between(start, end); // or alternatively long daysBetween = start.until(end, DAYS);
Specification for implementors
Implementations must begin by checking to ensure that the input temporal object is of the same observable type as the implementation. They must then perform the calculation for all instances of ChronoUnit. A DateTimeException must be thrown for ChronoUnit instances that are unsupported.
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 input temporal as the second argument.
In summary, implementations must behave in a manner equivalent to this code:
// check input temporal is the same type as this class if (unit instanceof ChronoUnit) { // if unit is supported, then calculate and return result // else throw DateTimeException for unsupported units } return unit.between(this, endTemporal);
The target object must not be altered by this method.
Override:
Temporal#untilParams:
Name | Type | Attribute | Description |
endExclusive | * | ||
unit | * |
Return:
* |
public withDayOfMonth(dayOfMonth: int): OffsetDateTime source
Params:
Name | Type | Attribute | Description |
dayOfMonth | int |
public withDayOfYear(dayOfYear: int): OffsetDateTime source
Params:
Name | Type | Attribute | Description |
dayOfYear | int |
public withHour(hour: int): OffsetDateTime source
Params:
Name | Type | Attribute | Description |
hour | int |
public withMinute(minute: int): OffsetDateTime source
Params:
Name | Type | Attribute | Description |
minute | int |
public withMonth(month: int): OffsetDateTime source
Params:
Name | Type | Attribute | Description |
month | int |
public withNano(nanoOfSecond: int): OffsetDateTime source
Params:
Name | Type | Attribute | Description |
nanoOfSecond | int |
public withOffsetSameInstant(offset: ZoneOffset): OffsetDateTime source
Params:
Name | Type | Attribute | Description |
offset | ZoneOffset |
public withOffsetSameLocal(offset: ZoneOffset): OffsetDateTime source
Params:
Name | Type | Attribute | Description |
offset | ZoneOffset |
public withSecond(second: int): OffsetDateTime source
Params:
Name | Type | Attribute | Description |
second | int |
public withYear(year: int): OffsetDateTime source
Params:
Name | Type | Attribute | Description |
year | int |