Package com.ethlo.time
Class Duration
java.lang.Object
com.ethlo.time.Duration
- All Implemented Interfaces:
Comparable<Duration>
Represents a precise duration in seconds and nanoseconds.
The nanoseconds field is always positive, with the sign absorbed by the seconds field.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longstatic final longstatic final intstatic final longstatic final longstatic final longstatic final longstatic final Duration -
Method Summary
Modifier and TypeMethodDescriptionabs()Returns the absolute durationAdds another duration to this one.intbooleanintgetNanos()Returns the nanosecond component of this duration.longReturns the number of seconds in this duration.inthashCode()negate()Negates this duration.Returns a normalized string representation of this duration.static Durationof(long seconds, int nanos) static DurationofDays(long days) Creates a duration from days.static DurationofHours(long hours) Creates a duration from hours.static DurationofMicros(long micros) Creates a duration from microseconds.static DurationofMillis(long millis) Creates a duration from milliseconds.static DurationofMinutes(long minutes) Creates a duration from minutes.static DurationofNanos(long nanos) Creates a duration from nanoseconds.static DurationofSeconds(long seconds) Creates a duration from seconds.static DurationofWeeks(long weeks) Creates a duration from weeks.plusHours(long hours) plusMinutes(long minutes) plusNanos(long nanos) plusSeconds(long seconds) Subtracts another duration from this one.timeline()Computes anInstantthat represents this duration on the timeline from nowComputes anInstantthat represents this duration on the timeline from a given instant.toString()
-
Field Details
-
ZERO
-
NANOS_PER_SECOND
public static final int NANOS_PER_SECOND- See Also:
-
SECONDS_PER_MINUTE
public static final long SECONDS_PER_MINUTE- See Also:
-
SECONDS_PER_HOUR
public static final long SECONDS_PER_HOUR- See Also:
-
SECONDS_PER_DAY
public static final long SECONDS_PER_DAY- See Also:
-
SECONDS_PER_WEEK
public static final long SECONDS_PER_WEEK- See Also:
-
NANOS_PER_MICROSECOND
public static final long NANOS_PER_MICROSECOND- See Also:
-
NANOS_PER_MILLISECOND
public static final long NANOS_PER_MILLISECOND- See Also:
-
-
Method Details
-
ofMillis
Creates a duration from milliseconds.- Parameters:
millis- The number of milliseconds.- Returns:
- A corresponding Duration instance.
-
ofMicros
Creates a duration from microseconds.- Parameters:
micros- The number of microseconds.- Returns:
- A corresponding Duration instance.
-
ofNanos
Creates a duration from nanoseconds.- Parameters:
nanos- The number of nanoseconds.- Returns:
- A corresponding Duration instance.
-
ofWeeks
Creates a duration from weeks.- Parameters:
weeks- The number of weeks.- Returns:
- A corresponding Duration instance.
-
ofDays
Creates a duration from days.- Parameters:
days- The number of days.- Returns:
- A corresponding Duration instance.
-
ofHours
Creates a duration from hours.- Parameters:
hours- The number of hours.- Returns:
- A corresponding Duration instance.
-
ofMinutes
Creates a duration from minutes.- Parameters:
minutes- The number of minutes.- Returns:
- A corresponding Duration instance.
-
ofSeconds
Creates a duration from seconds.- Parameters:
seconds- The number of seconds.- Returns:
- A corresponding Duration instance.
-
of
-
getSeconds
public long getSeconds()Returns the number of seconds in this duration.- Returns:
- The seconds value.
-
getNanos
public int getNanos()Returns the nanosecond component of this duration.- Returns:
- The nanosecond value.
-
normalized
Returns a normalized string representation of this duration.- Returns:
- The normalized duration string.
-
timeline
Computes anInstantthat represents this duration on the timeline from now- Returns:
- The computed instant representing the point on the timeline
-
timeline
Computes anInstantthat represents this duration on the timeline from a given instant.- Parameters:
instant- The reference instant.- Returns:
- The computed instant representing the point on the timeline
-
add
Adds another duration to this one.- Parameters:
other- The duration to add.- Returns:
- A new Duration representing the sum.
-
subtract
Subtracts another duration from this one.- Parameters:
other- The duration to subtract.- Returns:
- A new Duration representing the difference.
-
negate
Negates this duration.- Returns:
- A new Duration with the opposite sign.
-
abs
Returns the absolute duration- Returns:
- the absolute duration
-
equals
-
hashCode
public int hashCode() -
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<Duration>
-
plusHours
-
plusMinutes
-
plusSeconds
-
plusNanos
-