Package org.apache.avro.util
Class TimePeriod
java.lang.Object
org.apache.avro.util.TimePeriod
- All Implemented Interfaces:
Serializable
,TemporalAmount
A temporal amount to model an Avro duration
(the logical type).
It consists of a number of months, days and milliseconds, all modelled as an unsigned integer.
Compared to java.time.Period
, this class has a smaller range
('only' supporting a little less than 358 million years), and cannot support
negative time periods.
Compared to java.time.Duration
, this class has less
precision (milliseconds compared to nanoseconds), cannot support negative
durations, and has a much smaller range. Where java.time.Duration
supports fixed ranges up to about 68 years, TimePeriod
can only
handle about 49 days.
Comparison with the regular java.time
classes:
TimePeriod | Period |
Duration |
|
---|---|---|---|
Precision | milliseconds | days | nanoseconds |
Time range (approx.) | 0 - 49 days | unsupported | -68 - 68 years |
Date range (approx.) | 0 to 370 million years | -2.3 to 2.3 billion years | unsupported |
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionboolean
static TimePeriod
from
(TemporalAmount amount) long
get
(TemporalUnit unit) long
getDays()
long
long
getUnits()
int
hashCode()
boolean
Determines if the TimePeriod is date based (i.e., if its milliseconds component is 0).boolean
Determines if the TimePeriod is time based (i.e., if its months and days components are 0).static TimePeriod
of
(long months, long days, long millis) Create a TimePeriod from a number of months, days and millisecondssubtractFrom
(Temporal temporal) toPeriod()
toString()
-
Method Details
-
from
- Parameters:
amount
- a temporal amount- Returns:
- the corresponding TimePeriod
-
of
Create a TimePeriod from a number of months, days and milliseconds- Parameters:
months
- a number of monthsdays
- a number of daysmillis
- a number of milliseconds- Returns:
- the corresponding TimePeriod
- Throws:
ArithmeticException
- if any of the parameters does not fit an unsigned long (0..4294967296)
-
toDuration
-
toPeriod
-
isDateBased
public boolean isDateBased()Determines if the TimePeriod is date based (i.e., if its milliseconds component is 0).- Returns:
true
iff the TimePeriod is date based
-
isTimeBased
public boolean isTimeBased()Determines if the TimePeriod is time based (i.e., if its months and days components are 0).- Returns:
true
iff the TimePeriod is time based
-
getMonths
public long getMonths() -
getDays
public long getDays() -
getMillis
public long getMillis() -
get
- Specified by:
get
in interfaceTemporalAmount
-
getUnits
- Specified by:
getUnits
in interfaceTemporalAmount
-
addTo
- Specified by:
addTo
in interfaceTemporalAmount
-
subtractFrom
- Specified by:
subtractFrom
in interfaceTemporalAmount
-
equals
-
hashCode
public int hashCode() -
toString
-