Top Description Inners Constructors Methods
org.threeten.extra

public final Class Temporals

extends Object
Class Inheritance
Static Imports
java.time.temporal.ChronoField.DAY_OF_WEEK, .ChronoUnit.DAYS, .ChronoUnit.ERAS, .ChronoUnit.FOREVER, .ChronoUnit.WEEKS

Additional utilities for working with temporal classes.

This includes:

Implementation Requirements:

This is a thread-safe utility class. All returned classes are immutable and thread-safe.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
Temporals.Adjuster

Enum implementing the adjusters.

private static class
Temporals.BigDecimalSeconds

Useful Duration constants expressed as BigDecimal seconds with a scale of 9.

Constructor Summary

AccessConstructor and Description
private
Temporals()

Restricted constructor.

Method Summary

Modifier and TypeMethod and Description
public static ChronoUnit

Returns:

the converted unit, not null
chronoUnit
(TimeUnit
the unit to convert, not null
unit
)

Converts a TimeUnit to a ChronoUnit.

public static long[]

Returns:

the conversion array, element 0 is the signed whole number, element 1 is the signed remainder in terms of the input unit, not null
convertAmount
(long
the input amount in terms of the fromUnit
amount
,
TemporalUnit
the unit to convert from, not null
fromUnit
,
TemporalUnit
the unit to convert to, not null
toUnit
)

Converts an amount from one unit to another.

public static Duration

Returns:

a Duration, not null
durationFromBigDecimalSeconds
(BigDecimal
the number of seconds to convert, positive or negative
seconds
)

Converts a BigDecimal representing seconds to a duration, saturating if necessary.

public static Duration

Returns:

a Duration, not null
durationFromDoubleSeconds
(double
the number of seconds to convert, positive or negative
seconds
)

Converts a double representing seconds to a duration, saturating if necessary.

public static BigDecimal

Returns:

the BigDecimal equivalent of the duration, in seconds with a scale of 9
durationToBigDecimalSeconds
(Duration
the duration to convert, not null
duration
)

Converts a duration to a BigDecimal with a scale of 9.

public static double

Returns:

the double equivalent of the duration, in seconds
durationToDoubleSeconds
(Duration
the duration to convert, not null
duration
)

Converts a duration to a double.

private static boolean
private static int
public static Duration

Returns:

the multiplied duration, not null
multiply
(Duration
the duration to multiply, not null
duration
,
double
the multiplication factor
multiplicand
)

Multiplies a duration by a double.

public static TemporalAdjuster

Returns:

the next working day adjuster, not null
nextWorkingDay
()

Returns an adjuster that returns the next working day, ignoring Saturday and Sunday.

public static TemporalAdjuster

Returns:

the next working day or same adjuster, not null
nextWorkingDayOrSame
()

Returns an adjuster that returns the next working day or same day if already working day, ignoring Saturday and Sunday.

public static <
the type of the parsed date-time
T
>
T

Returns:

the parsed date-time, not null
parseFirstMatching
(CharSequence
the text to parse, not null
text
,
TemporalQuery<T>
the query defining the type to parse to, not null
query
,
DateTimeFormatter...
the formatters to try, not null
formatters
)

Parses the text using one of the formatters.

public static TemporalAdjuster

Returns:

the previous working day adjuster, not null
previousWorkingDay
()

Returns an adjuster that returns the previous working day, ignoring Saturday and Sunday.

public static TemporalAdjuster

Returns:

the previous working day or same adjuster, not null
previousWorkingDayOrSame
()

Returns an adjuster that returns the previous working day or same day if already working day, ignoring Saturday and Sunday.

public static TimeUnit

Returns:

the converted unit, not null
timeUnit
(ChronoUnit
the unit to convert, not null
unit
)

Converts a ChronoUnit to a TimeUnit.

private static void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Temporalsback to summary
private Temporals()

Restricted constructor.

Method Detail

chronoUnitback to summary
public static ChronoUnit chronoUnit(TimeUnit unit)

Converts a TimeUnit to a ChronoUnit.

This handles the seven units declared in TimeUnit.

Parameters
unit:TimeUnit

the unit to convert, not null

Returns:ChronoUnit

the converted unit, not null

convertAmountback to summary
public static long[] convertAmount(long amount, TemporalUnit fromUnit, TemporalUnit toUnit)

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.

Parameters
amount:long

the input amount in terms of the fromUnit

fromUnit:TemporalUnit

the unit to convert from, not null

toUnit:TemporalUnit

the unit to convert to, not null

Returns: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

Exceptions
DateTimeException:
if the units cannot be converted
UnsupportedTemporalTypeException:
if the units are not supported
ArithmeticException:
if numeric overflow occurs
durationFromBigDecimalSecondsback to summary
public static Duration durationFromBigDecimalSeconds(BigDecimal seconds)

Converts a BigDecimal representing seconds to a duration, saturating if necessary.

No exception is thrown by this method. Numbers are rounded up to the nearest nanosecond (away from zero). The duration will saturate at the biggest positive or negative Duration.

Parameters
seconds:BigDecimal

the number of seconds to convert, positive or negative

Returns:Duration

a Duration, not null

durationFromDoubleSecondsback to summary
public static Duration durationFromDoubleSeconds(double seconds)

Converts a double representing seconds to a duration, saturating if necessary.

No exception is thrown by this method. Numbers are rounded up to the nearest nanosecond (away from zero). The duration will saturate at the biggest positive or negative Duration.

Parameters
seconds:double

the number of seconds to convert, positive or negative

Returns:Duration

a Duration, not null

durationToBigDecimalSecondsback to summary
public static BigDecimal durationToBigDecimalSeconds(Duration duration)

Converts a duration to a BigDecimal with a scale of 9.

Parameters
duration:Duration

the duration to convert, not null

Returns:BigDecimal

the BigDecimal equivalent of the duration, in seconds with a scale of 9

durationToDoubleSecondsback to summary
public static double durationToDoubleSeconds(Duration duration)

Converts a duration to a double.

Parameters
duration:Duration

the duration to convert, not null

Returns:double

the double equivalent of the duration, in seconds

isPreciseback to summary
private static boolean isPrecise(TemporalUnit unit)
monthMonthFactorback to summary
private static int monthMonthFactor(TemporalUnit unit, TemporalUnit fromUnit, TemporalUnit toUnit)
multiplyback to summary
public static Duration multiply(Duration duration, double multiplicand)

Multiplies a duration by a double.

The amount is rounded away from zero, thus the result is only zero if zero is passed in. See durationToBigDecimalSeconds(Duration) and durationFromBigDecimalSeconds(BigDecimal). Note that due to the rounding up, 1 nanosecond multiplied by any number smaller than 1 will still be 1 nanosecond.

Parameters
duration:Duration

the duration to multiply, not null

multiplicand:double

the multiplication factor

Returns:Duration

the multiplied duration, not null

nextWorkingDayback to summary
public static TemporalAdjuster nextWorkingDay()

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.

Returns:TemporalAdjuster

the next working day adjuster, not null

nextWorkingDayOrSameback to summary
public static TemporalAdjuster nextWorkingDayOrSame()

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.

Returns:TemporalAdjuster

the next working day or same adjuster, not null

parseFirstMatchingback to summary
public static <T> T parseFirstMatching(CharSequence text, TemporalQuery<T> query, DateTimeFormatter... formatters)

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, 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.
Parameters
<T>
the type of the parsed date-time
text:CharSequence

the text to parse, not null

query:TemporalQuery<T>

the query defining the type to parse to, not null

formatters:DateTimeFormatter[]

the formatters to try, not null

Returns:T

the parsed date-time, not null

Exceptions
DateTimeParseException:
if unable to parse the requested result
previousWorkingDayback to summary
public static TemporalAdjuster previousWorkingDay()

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.

Returns:TemporalAdjuster

the previous working day adjuster, not null

previousWorkingDayOrSameback to summary
public static TemporalAdjuster previousWorkingDayOrSame()

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.

Returns:TemporalAdjuster

the previous working day or same adjuster, not null

timeUnitback to summary
public static TimeUnit timeUnit(ChronoUnit unit)

Converts a ChronoUnit to a TimeUnit.

This handles the seven units declared in TimeUnit.

Parameters
unit:ChronoUnit

the unit to convert, not null

Returns:TimeUnit

the converted unit, not null

Exceptions
IllegalArgumentException:
if the unit cannot be converted
validateUnitback to summary
private static void validateUnit(TemporalUnit unit)
org.threeten.extra back to summary

private sealed Enum Temporals.Adjuster

extends Enum<Temporals.Adjuster>
implements TemporalAdjuster
Class Inheritance
All Implemented Interfaces
java.time.temporal.TemporalAdjuster

Enum implementing the adjusters.

Field Summary

Modifier and TypeField and Description
public static final Temporals.Adjuster
NEXT_WORKING

Next working day adjuster.

public static final Temporals.Adjuster
NEXT_WORKING_OR_SAME

Next working day or same adjuster.

public static final Temporals.Adjuster
PREVIOUS_WORKING

Previous working day adjuster.

public static final Temporals.Adjuster
PREVIOUS_WORKING_OR_SAME

Previous working day or same adjuster.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Temporals.Adjuster
public static Temporals.Adjuster[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

NEXT_WORKINGback to summary
public static final Temporals.Adjuster NEXT_WORKING

Next working day adjuster.

NEXT_WORKING_OR_SAMEback to summary
public static final Temporals.Adjuster NEXT_WORKING_OR_SAME

Next working day or same adjuster.

PREVIOUS_WORKINGback to summary
public static final Temporals.Adjuster PREVIOUS_WORKING

Previous working day adjuster.

PREVIOUS_WORKING_OR_SAMEback to summary
public static final Temporals.Adjuster PREVIOUS_WORKING_OR_SAME

Previous working day or same adjuster.

Constructor Detail

Adjusterback to summary
private Adjuster()

Method Detail

valueOfback to summary
public static Temporals.Adjuster valueOf(String name)
valuesback to summary
public static Temporals.Adjuster[] values()
org.threeten.extra back to summary

private final Class Temporals.BigDecimalSeconds

extends Object
Class Inheritance

Useful Duration constants expressed as BigDecimal seconds with a scale of 9.

Field Summary

Modifier and TypeField and Description
public static final BigDecimal
public static final BigDecimal

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

MAXback to summary
public static final BigDecimal MAX
MINback to summary
public static final BigDecimal MIN

Constructor Detail

BigDecimalSecondsback to summary
private BigDecimalSeconds()