Temporals
Additional utilities for working with temporal classes.
This includes:
- adjusters that ignore Saturday/Sunday weekends
- conversion between
TimeUnit
andChronoUnit
- converting an amount to another unit
Static Method Summary
Static Public Methods | ||
public static |
convertAmount(amount: long, fromUnit: TemporalUnit, toUnit: TemporalUnit): long[] Converts an amount from one unit to another. |
|
public static |
Returns an adjuster that returns the next working day, ignoring Saturday and Sunday. |
|
public static |
Returns an adjuster that returns the next working day or same day if already working day, ignoring Saturday and Sunday. |
|
public static |
parseFirstMatching(text: string, query: TemporalQuery, formatters: DateTimeFormatter[]): * Parses the text using one of the formatters. |
|
public static |
Returns an adjuster that returns the previous working day, ignoring Saturday and Sunday. |
|
public static |
Returns an adjuster that returns the previous working day or same day if already working day, ignoring Saturday and Sunday. |
Static Public Methods
public static convertAmount(amount: long, fromUnit: TemporalUnit, toUnit: TemporalUnit): long[] source
Converts an amount from one unit to another.
This works on the units in ChronoUnit
and IsoFields
.
The DAYS
and WEEKS
units are handled as exact multiple of 24 hours.
The ERAS
and FOREVER
units are not supported.
Params:
Name | Type | Attribute | Description |
amount | long | the input amount in terms of the |
|
fromUnit | TemporalUnit | the unit to convert from, not null |
|
toUnit | TemporalUnit | the unit to convert to, not null |
Return:
long[] | the conversion array, element 0 is the signed whole number, element 1 is the signed remainder in terms of the input unit, not null |
Throw:
* |
DateTimeException if the units cannot be converted |
* |
UnsupportedTemporalTypeException if the units are not supported |
* |
ArithmeticException if numeric overflow occurs |
public static nextWorkingDay(): TemporalAdjuster source
Returns an adjuster that returns the next working day, ignoring Saturday and Sunday.
Some territories have weekends that do not consist of Saturday and Sunday. No implementation is supplied to support this, however an adjuster can be easily written to do so.
public static nextWorkingDayOrSame(): TemporalAdjuster source
Returns an adjuster that returns the next working day or same day if already working day, ignoring Saturday and Sunday.
Some territories have weekends that do not consist of Saturday and Sunday. No implementation is supplied to support this, however an adjuster can be easily written to do so.
public static parseFirstMatching(text: string, query: TemporalQuery, formatters: DateTimeFormatter[]): * source
Parses the text using one of the formatters.
This will try each formatter in turn, attempting to fully parse the specified text.
The temporal query is typically a method reference to a from(TemporalAccessor)
method.
For example:
LocalDateTime dt = Temporals.parseFirstMatching(str, LocalDateTime.FROM, fm1, fm2, fm3);
If the parse completes without reading the entire length of the text, or a problem occurs during parsing or merging, then an exception is thrown.
Params:
Name | Type | Attribute | Description |
text | string | the text to parse, not null |
|
query | TemporalQuery | the query defining the type to parse to, not null |
|
formatters | DateTimeFormatter[] | the formatters to try, not null |
Return:
* | the parsed date-time, not null |
Throw:
if unable to parse the requested result |
public static previousWorkingDay(): TemporalAdjuster source
Returns an adjuster that returns the previous working day, ignoring Saturday and Sunday.
Some territories have weekends that do not consist of Saturday and Sunday. No implementation is supplied to support this, however an adjuster can be easily written to do so.
public static previousWorkingDayOrSame(): TemporalAdjuster source
Returns an adjuster that returns the previous working day or same day if already working day, ignoring Saturday and Sunday.
Some territories have weekends that do not consist of Saturday and Sunday. No implementation is supplied to support this, however an adjuster can be easily written to do so.