public final class Temporals
extends java.lang.Object
This includes:
TimeUnit
and ChronoUnit
Modifier and Type | Method | Description |
---|---|---|
static java.time.temporal.ChronoUnit |
chronoUnit(java.util.concurrent.TimeUnit unit) |
Converts a
TimeUnit to a ChronoUnit . |
static long[] |
convertAmount(long amount,
java.time.temporal.TemporalUnit fromUnit,
java.time.temporal.TemporalUnit toUnit) |
Converts an amount from one unit to another.
|
static java.time.temporal.TemporalAdjuster |
nextWorkingDay() |
Returns an adjuster that returns the next working day, ignoring Saturday and Sunday.
|
static java.time.temporal.TemporalAdjuster |
nextWorkingDayOrSame() |
Returns an adjuster that returns the next working day or same day if already working day, ignoring Saturday and Sunday.
|
static <T> T |
parseFirstMatching(java.lang.CharSequence text,
java.time.temporal.TemporalQuery<T> query,
java.time.format.DateTimeFormatter... formatters) |
Parses the text using one of the formatters.
|
static java.time.temporal.TemporalAdjuster |
previousWorkingDay() |
Returns an adjuster that returns the previous working day, ignoring Saturday and Sunday.
|
static java.time.temporal.TemporalAdjuster |
previousWorkingDayOrSame() |
Returns an adjuster that returns the previous working day or same day if already working day, ignoring Saturday and Sunday.
|
static java.util.concurrent.TimeUnit |
timeUnit(java.time.temporal.ChronoUnit unit) |
Converts a
ChronoUnit to a TimeUnit . |
public static java.time.temporal.TemporalAdjuster nextWorkingDay()
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 java.time.temporal.TemporalAdjuster nextWorkingDayOrSame()
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 java.time.temporal.TemporalAdjuster previousWorkingDay()
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 java.time.temporal.TemporalAdjuster previousWorkingDayOrSame()
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 <T> T parseFirstMatching(java.lang.CharSequence text, java.time.temporal.TemporalQuery<T> query, java.time.format.DateTimeFormatter... 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, fmt1, 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.
T
- the type of the parsed date-timetext
- the text to parse, not nullquery
- the query defining the type to parse to, not nullformatters
- the formatters to try, not nulljava.time.format.DateTimeParseException
- if unable to parse the requested resultpublic static java.time.temporal.ChronoUnit chronoUnit(java.util.concurrent.TimeUnit unit)
TimeUnit
to a ChronoUnit
.
This handles the seven units declared in TimeUnit
.
unit
- the unit to convert, not nullpublic static java.util.concurrent.TimeUnit timeUnit(java.time.temporal.ChronoUnit unit)
ChronoUnit
to a TimeUnit
.
This handles the seven units declared in TimeUnit
.
unit
- the unit to convert, not nulljava.lang.IllegalArgumentException
- if the unit cannot be convertedpublic static long[] convertAmount(long amount, java.time.temporal.TemporalUnit fromUnit, java.time.temporal.TemporalUnit toUnit)
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.
amount
- the input amount in terms of the fromUnit
fromUnit
- the unit to convert from, not nulltoUnit
- the unit to convert to, not nulljava.time.DateTimeException
- if the units cannot be convertedjava.time.temporal.UnsupportedTemporalTypeException
- if the units are not supportedjava.lang.ArithmeticException
- if numeric overflow occursCopyright © 2010–2018 ThreeTen.org. All rights reserved.