OffsetTime
Extends:
A time with an offset from UTC/Greenwich in the ISO-8601 calendar system, such as 10:15:30+01:00.
Static Method Summary
Static Public Methods | ||
public static |
from(temporal: TemporalAccessor): OffsetTime |
|
public static |
now(clockOrZone: Clock | ZoneId): OffsetTime |
|
public static |
of(): OffsetTime |
|
public static |
ofInstant(instant: Instant, zone: ZoneId): OffsetTime |
|
public static |
ofNumbers(hour: int, minute: int, second: int, nanoOfSecond: int, offset: ZoneOffset): OffsetTime |
|
public static |
ofTimeAndOffset(time: LocalTime, offset: ZoneOffset): OffsetTime |
|
public static |
parse(text: string, formatter: DateTimeFormatter): OffsetTime |
Method Summary
Public Methods | ||
public |
adjustInto(temporal: TemporalAdjuster): Temporal |
|
public |
atDate(date: LocalDate): OffsetDateTime |
|
public |
compareTo(other: OffsetTime): int |
|
public |
equals(other: *): boolean |
|
public |
format(formatter: DateTimeFormatter): string |
|
public |
get(field: TemporalField): number |
|
public |
getLong(field: TemporalField): number |
|
public |
hashCode(): number |
|
public |
hour(): int |
|
public |
isAfter(other: OffsetTime): boolean |
|
public |
isBefore(other: OffsetTime): boolean |
|
public |
isEqual(other: OffsetTime): boolean |
|
public |
isSupported(fieldOrUnit: TemporalField | TemporalUnit): boolean |
|
public |
minusHours(hours: number): OffsetTime |
|
public |
minusMinutes(minutes: number): OffsetTime |
|
public |
minusNanos(nanos: number): OffsetTime |
|
public |
minusSeconds(seconds: number): OffsetTime |
|
public |
minute(): int |
|
public |
nano(): int |
|
public |
offset(): ZoneOffset |
|
public |
plusHours(hours: int): OffsetTime |
|
public |
plusMinutes(minutes: int): OffsetTime |
|
public |
plusNanos(nanos: int): OffsetTime |
|
public |
plusSeconds(seconds: int): OffsetTime |
|
public |
query(query: TemporalQuery): * |
|
public |
range(field: TemporalField): ValueRange |
|
public |
second(): int |
|
public |
toJSON(): string |
|
public |
|
|
public |
toString(): string |
|
public |
truncatedTo(unit: TemporalUnit): OffsetTime |
|
public |
until(endExclusive: Temporal, unit: TemporalUnit): number |
|
public |
withHour(hour: int): OffsetTime |
|
public |
withMinute(minute: int): OffsetTime |
|
public |
withNano(nano: int): OffsetTime |
|
public |
withOffsetSameInstant(offset: ZoneOffset): OffsetTime |
|
public |
withOffsetSameLocal(offset: ZoneOffset): OffsetTime |
|
public |
withSecond(second: int): OffsetTime |
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: TemporalAccessor): OffsetTime source
Params:
Name | Type | Attribute | Description |
temporal | TemporalAccessor |
|
public static now(clockOrZone: Clock | ZoneId): OffsetTime source
public static ofInstant(instant: Instant, zone: ZoneId): OffsetTime source
public static ofNumbers(hour: int, minute: int, second: int, nanoOfSecond: int, offset: ZoneOffset): OffsetTime source
Params:
Name | Type | Attribute | Description |
hour | int | ||
minute | int | ||
second | int | ||
nanoOfSecond | int | ||
offset | ZoneOffset |
public static ofTimeAndOffset(time: LocalTime, offset: ZoneOffset): OffsetTime source
Params:
Name | Type | Attribute | Description |
time | LocalTime | ||
offset | ZoneOffset |
public static parse(text: string, formatter: DateTimeFormatter): OffsetTime source
Params:
Name | Type | Attribute | Description |
text | string | ||
formatter | DateTimeFormatter |
Public Methods
public adjustInto(temporal: TemporalAdjuster): Temporal source
Params:
Name | Type | Attribute | Description |
temporal | TemporalAdjuster | the target object to be adjusted, not null |
Throw:
if unable to make the adjustment |
|
if numeric overflow occurs |
public atDate(date: LocalDate): OffsetDateTime source
Params:
Name | Type | Attribute | Description |
date | LocalDate | the date to combine with, not null |
public compareTo(other: OffsetTime): int source
Params:
Name | Type | Attribute | Description |
other | OffsetTime | the other time to compare to, not null |
Return:
int | the comparator value, negative if less, positive if greater |
Throw:
if |
public equals(other: *): boolean source
Params:
Name | Type | Attribute | Description |
other | * | the object to check, null returns false |
Return:
boolean | true if this is equal to the other time |
public format(formatter: DateTimeFormatter): string source
Params:
Name | Type | Attribute | Description |
formatter | DateTimeFormatter | the formatter to use, not null |
Return:
string | the formatted time string, not null |
Throw:
if an error occurs during printing |
public get(field: TemporalField): number 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 | TemporalField | the field to get, not null |
Return:
number | the value for the field |
Throw:
if a value for the field cannot be obtained |
|
if numeric overflow occurs |
public getLong(field: TemporalField): number source
Override:
TemporalAccessor#getLongParams:
Name | Type | Attribute | Description |
field | TemporalField | the field to get, not null |
Return:
number | the value for the field |
Throw:
if a value for the field cannot be obtained |
|
if numeric overflow occurs |
public isAfter(other: OffsetTime): boolean source
Params:
Name | Type | Attribute | Description |
other | OffsetTime | the other time to compare to, not null |
Return:
boolean | true if this is after the specified time |
Throw:
if |
public isBefore(other: OffsetTime): boolean source
Params:
Name | Type | Attribute | Description |
other | OffsetTime | the other time to compare to, not null |
Return:
boolean | true if this point is before the specified time |
Throw:
if |
public isEqual(other: OffsetTime): boolean source
Params:
Name | Type | Attribute | Description |
other | OffsetTime | the other time to compare to, not null |
Return:
boolean |
Throw:
if |
public isSupported(fieldOrUnit: TemporalField | TemporalUnit): boolean 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 | TemporalField | TemporalUnit | the field to check, null returns false |
Return:
boolean | true if the field is supported on this time, false if not |
public minusHours(hours: number): OffsetTime source
Params:
Name | Type | Attribute | Description |
hours | number |
public minusMinutes(minutes: number): OffsetTime source
Params:
Name | Type | Attribute | Description |
minutes | number |
public minusNanos(nanos: number): OffsetTime source
Params:
Name | Type | Attribute | Description |
nanos | number |
public minusSeconds(seconds: number): OffsetTime source
Params:
Name | Type | Attribute | Description |
seconds | number |
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 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 query(query: TemporalQuery): * 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 | TemporalQuery | the query to invoke, not null |
Return:
* | the query result, null may be returned (defined by the query) |
Throw:
if unable to query (defined by the query) |
|
if numeric overflow occurs (defined by the query) |
public range(field: TemporalField): ValueRange 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 | TemporalField | the field to query the range for, not null |
Throw:
if the range for the field cannot be obtained |
public truncatedTo(unit: TemporalUnit): OffsetTime source
Params:
Name | Type | Attribute | Description |
unit | TemporalUnit | the unit to truncate to, not null |
Throw:
if unable to truncate |
public until(endExclusive: Temporal, unit: TemporalUnit): number 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 | Temporal | the end time, which is converted to a LocalTime, not null |
|
unit | TemporalUnit | the unit to measure the period in, not null |
Return:
number | the amount of the period between this time and the end time |
Throw:
if the period cannot be calculated |
|
if numeric overflow occurs |
public withHour(hour: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
hour | int |
public withMinute(minute: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
minute | int |
public withNano(nano: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
nano | int |
public withOffsetSameInstant(offset: ZoneOffset): OffsetTime source
Params:
Name | Type | Attribute | Description |
offset | ZoneOffset |
public withOffsetSameLocal(offset: ZoneOffset): OffsetTime source
Params:
Name | Type | Attribute | Description |
offset | ZoneOffset |
public withSecond(second: int): OffsetTime source
Params:
Name | Type | Attribute | Description |
second | int |