public final class Duration extends Object implements IIvyDataObject, Comparable<Duration>
Durations are a component of time intervals and define the amount of intervening time in a time interval. So, if you have the time interval between yesterday at noon and today 1 pm, then the corresponding duration is one day and one hour (assuming that daylight saving and timezone did not change). Durations are measured in years, months, days, hours, minutes and seconds.
This implementation uses ISO 8601 for representation which uses the format P[n]Y[n]M[n]DT[n]H[n]M[n]S to represent a duration. Every character in this string is a field descriptor or a separator:
Modifier and Type | Field and Description |
---|---|
static Duration |
INVALID
An invalid duration object.
|
static Duration |
UNINITIALIZED_DURATION
An uninitialized duration object.
|
Constructor and Description |
---|
Duration(int _years,
int _monthes,
int _days,
int _hours,
int _minutes,
int _seconds)
Creates a new duration object.
|
Duration(long sec)
Creates a normalized duration with a given amount of seconds.
|
Duration(String literal)
Parses a Duration literal and creates a new corresponding Date object.
|
Duration(String fields,
int... values)
Creates a new Duration object.
|
Modifier and Type | Method and Description |
---|---|
Duration |
add(Duration duration)
Adds a duration to this date.
|
Duration |
clone()
Creates a clone of this object.
|
int |
compareTo(Duration duration)
Compares two durations lexicograohically.
|
Duration |
divide(Number divisor)
Divides the Duration by a divisor.
|
boolean |
equals(Object duration)
Test two objects for equality.
|
int |
getDays()
Returns the days of the duration.
|
int |
getHours()
Returns the hours of the duration.
|
int |
getMinutes()
Returns the minutes of the duration.
|
int |
getMonths()
Returns the monthes of the duration.
|
int |
getSeconds()
Returns the seconds of the duration.
|
int |
getYears()
Returns the years of the duration.
|
int |
hashCode()
A hashcode; the number of days after 1970-01-01.
|
Duration |
minus(Duration duration)
Subtracts a duration to this date.
|
Duration |
multiply(Number factor)
Multiplies the Duration with a factor.
|
Duration |
normalize()
Returns a normalized duration.
|
long |
toNumber()
|
String |
toString()
Returns the duration as String in the ISO-8601 format, see also
Duration.toIsoFormat() . |
Time |
toTime()
|
deepClone
public static final Duration UNINITIALIZED_DURATION
public static final Duration INVALID
public Duration(int _years, int _monthes, int _days, int _hours, int _minutes, int _seconds)
_years
- The years of the duration._monthes
- The months of the duration._days
- The days of the duration._hours
- The days of the duration._minutes
- The minutes of the duration._seconds
- The seconds of the duration.public Duration(String fields, int... values)
Example:
Duration("YMD", 2,5,3)
creates a duration of
2 years, 5 months and 3 days.Duration("DTMS", 2,5,3)
creates a duration of
2 days, 5 minutes and 3 seconds.fields
- A String describing which fields are set
in the following arguments.
Every character in this string is a field descriptor
or a separator. The following characters are allowed
in this string:
values
- The values of the fields.
If the first argument does not contain the separator T
the number of values must be equal to the number of
non-separator characters in the first argument.IllegalArgumentException
- if number of field descriptors (excluding T)
is not equal to number of values or if an unknown field descriptor is foundpublic Duration(String literal)
literal
- A duration literal literal has the following format:
P[n]Y[n]M[n]DT[n]H[n]M[n]S.
Elements may be omitted if their value is zero.
IllegalArgumentException
- if the argument has an illegal format.public Duration(long sec)
sec
- public Duration normalize()
public int getYears()
public int getMonths()
public int getDays()
public int getHours()
public int getMinutes()
public int getSeconds()
public Duration add(Duration duration)
duration
- A duration (in seconds).public Duration minus(Duration duration)
duration
- A duration (in seconds).public Duration multiply(Number factor)
factor
- public Duration divide(Number divisor)
divisor
- public long toNumber()
Duration
to a Number
;
this is the number of second in this duration.
A month has 30 days and a year has 365 days for this computation.Number
of seconds corresponding to this duration.public Time toTime()
Time
of seconds corresponding to this duration time part.public int compareTo(Duration duration)
duration
- Some other duration.public String toString()
Duration.toIsoFormat()
.toString
in class Object
Duration.toIsoFormat()
public boolean equals(Object duration)
public int hashCode()
public Duration clone()
clone
in interface IIvyDataObject
clone
in class Object
Copyright © 2024
AXON IVY AG
All Rights Reserved Documentation was generated
on April 28, 2024