Duration (API Reference)
Package com.here.time
Class Duration
java.lang.Object
com.here.time.Duration
- All Implemented Interfaces:
Comparable<Duration>
Represents duration in time (both positive and negative).
The duration is represented as number of seconds (see getSeconds())
and number of nanonseconds in a second (see getNano()).
Duration can be created from various units of time by calling on of
of* methods. The to* family of methods convert duration
to a value expressed in desired unit of time.
-
Method Summary
Modifier and TypeMethodDescriptionintbooleanintgetNano()longinthashCode()static DurationofDays(long days) Creates a duration representing specified number of days.static DurationofHours(long hours) Creates a duration representing specified number of hours.static DurationofMillis(long milliseconds) Creates a duration representing specified number of milliseconds.static DurationofMinutes(long minutes) Creates a duration representing specified number of hours.static DurationofNanos(long nanoseconds) Creates a duration representing specified number of nanoseconds.static DurationofSeconds(long seconds) Creates a duration representing specified number of seconds.static DurationofSeconds(long seconds, long nanoAdjustment) Creates a duration representing specified number of seconds and an adjustment in nanoseconds.longtoDays()Converts this duration to days.longSame astoDays().longtoHours()Converts this duration to hours.intGets the hours part of this duration.longtoMillis()Converts this duration to milliseconds.intGets the milliseconds part of this duration.longConverts this duration to minutes.intGets the minutes part of this duration.longtoNanos()Converts this duration to nanoseconds.intGets the nanoseconds part of this duration.longConverts this duration to seconds.intGets the seconds part of this duration.
-
Method Details
-
getNano
public int getNano()- Returns:
- The nanoseconds component of this duration.
-
getSeconds
public long getSeconds()- Returns:
- The seconds component of this duration.
-
ofDays
Creates a duration representing specified number of days. A Day is assumed to always be 24 hours.- Parameters:
days- The number of days.- Returns:
- The Duration representing the specified number of days.
- Throws:
ArithmeticException- if the input is outside the range possible to represent by a Duration
-
ofHours
Creates a duration representing specified number of hours. An hour is assumed to always be 60 minutes.- Parameters:
hours- The number of hours.- Returns:
- The Duration representing the specified number of hours.
- Throws:
ArithmeticException- if the input is outside the range possible to represent by a Duration
-
ofMinutes
Creates a duration representing specified number of hours. A minute is assumed to always be 60 seconds.- Parameters:
minutes- The number of minutes.- Returns:
- The Duration representing the specified number of minutes.
- Throws:
ArithmeticException- if the input is outside the range possible to represent by a Duration
-
ofSeconds
Creates a duration representing specified number of seconds.- Parameters:
seconds- The number of seconds.- Returns:
- The Duration representing the specified number of seconds.
-
ofSeconds
Creates a duration representing specified number of seconds and an adjustment in nanoseconds.- Parameters:
seconds- The number of seconds.nanoAdjustment- The nanosecond adjustment to the number of seconds.- Returns:
- The Duration representing the specified number of seconds, adjusted.
-
ofMillis
Creates a duration representing specified number of milliseconds.- Parameters:
milliseconds- The number of milliseconds.- Returns:
- The Duration representing the specified number of milliseconds.
-
ofNanos
Creates a duration representing specified number of nanoseconds.- Parameters:
nanoseconds- The number of nanoseconds.- Returns:
- The Duration representing the specified number of nanoseconds.
-
toNanos
Converts this duration to nanoseconds.- Returns:
- Total number of nanoseconds in this duration.
- Throws:
ArithmeticException- if the resulting value cannot be represented bylongtype.
-
toNanosPart
public int toNanosPart()Gets the nanoseconds part of this duration. Equals togetNano().- Returns:
- The nanoseconds part of this duration, value from 0 to 999999999.
-
toMillis
Converts this duration to milliseconds. Any data past milliseconds precision is simply discarded. There is no mathematical rounding, so a duration of 999999 nanoseconds will still be converted to 0 milliseconds.- Returns:
- Total number of milliseconds in this duration.
- Throws:
ArithmeticException- if the resulting value cannot be represented bylongtype.
-
toMillisPart
public int toMillisPart()Gets the milliseconds part of this duration.- Returns:
- The milliseconds part of this duration.
-
toSeconds
public long toSeconds()Converts this duration to seconds. Any data past seconds precision is simply discarded. There is no mathematical rounding, so a duration of 999 milliseconds will still be converted to 0 seconds.- Returns:
- Total number of seconds in this duration.
-
toSecondsPart
public int toSecondsPart()Gets the seconds part of this duration.- Returns:
- The seconds part of this duration, value from 0 to 59.
-
toMinutes
public long toMinutes()Converts this duration to minutes. Any data past minute precision is simply discarded. There is no mathematical rounding, so a duration of 59 seconds and 999 milliseconds will still be converted to 0 minutes.- Returns:
- Total number of minutes in this duration.
-
toMinutesPart
public int toMinutesPart()Gets the minutes part of this duration.- Returns:
- The minutes part of this duration, value from 0 to 59.
-
toHours
public long toHours()Converts this duration to hours. Any data past hour precision is simply discarded. There is no mathematical rounding, so a duration of 59 minutes and 59 seconds will still be converted to 0 hours.- Returns:
- The number of full hours in this duration.
-
toHoursPart
public int toHoursPart()Gets the hours part of this duration.- Returns:
- The hours part of this duration, value from 0 to 23.
-
toDays
public long toDays()Converts this duration to days. Any data past day precision is simply discarded. There is no mathematical rounding, so a duration of 23 hours 59 minutes and 59 seconds will still be converted to 0 days. Day is always assumed to be 24 hours.- Returns:
- The number of full days in this duration.
-
toDaysPart
public long toDaysPart()Same astoDays().- Returns:
- The number of full days in this duration.
-
compareTo
- Specified by:
compareToin interfaceComparable<Duration>
-
equals
-
hashCode
public int hashCode()
-