public final class Duration
extends java.lang.Object
Objects of this class are immutable.
| Constructor and Description |
|---|
Duration(int sign,
int weeks)
Create a duration of the given number of weeks.
|
Duration(int sign,
int days,
int time)
Create a duration of the given day and time values.
|
Duration(int sign,
int days,
int hours,
int minutes,
int seconds)
Create a duration of the given day and time values.
|
| Modifier and Type | Method and Description |
|---|---|
Duration |
addDuration(Duration other)
|
long |
addTo(java.util.TimeZone timezone,
long timestamp)
Add this duration to the given timestamp, taking daylight savings in the given time zone into account.
|
boolean |
equals(java.lang.Object obj) |
int |
getDays()
Return the days of this duration.
|
int |
getHours()
Return the hours of this duration.
|
int |
getMinutes()
Return the minutes of this duration.
|
int |
getRawDays()
Returns the actual number of days, without taking weeks into account.
|
int |
getSeconds()
Return the seconds of this duration.
|
int |
getSecondsOfDay()
Returns the time part in seconds.
|
int |
getSign()
Return the sign of this duration.
|
int |
getWeeks()
Return the weeks of this duration.
|
int |
hashCode() |
boolean |
isZero()
Returns whether this Duration represents zero time.
|
static Duration |
parse(java.lang.String durationString)
Parse the given Duration String to a
Duration value. |
long |
toMillis()
Returns the value of this Duration in milliseconds, assuming days of 24 hours.
|
java.lang.String |
toString() |
void |
writeTo(java.lang.StringBuilder builder)
Write the Duration String to the given
StringBuilder. |
void |
writeTo(java.io.Writer writer)
Write the Duration String to the given
Writer. |
public Duration(int sign,
int weeks)
sign - The factor that determines the sign. Must be either 1 or -1.weeks - The number of weeks of the duration.public Duration(int sign,
int days,
int hours,
int minutes,
int seconds)
sign - The factor that determines the sign. Must be either 1 or -1.days - The number of days of the duration.hours - The number of hours of the duration.minutes - The number of minutes of the duration.seconds - The number of seconds of the duration.public Duration(int sign,
int days,
int time)
sign - The factor that determines the sign. Must be either 1 or -1.days - The number of days of the duration.time - The time of the duration in seconds.public static Duration parse(java.lang.String durationString)
Duration value.durationString - A String that conforms to a Duration as specified in RFC 5545, Section 3.3.6.Duration instance.java.lang.IllegalArgumentException - if the Duration String is malformed.public boolean isZero()
true if all values are 0, false otherwise.public int getSign()
1 or -1.public int getWeeks()
0 if the number of days is not a multiple of 7 or the duration has a time
part.public int getDays()
0 if the number of days is a multiple of 7 and the duration has no time part.
Use getRawDays() to get the actual number of days.
public int getRawDays()
getDays() to get the number of days as in the resulting Duration
string.public int getHours()
public int getMinutes()
public int getSeconds()
public int getSecondsOfDay()
getHours() * 3600 + getMinutes * 60 + getSeconds()
but this method is faster than calling the above.
public long toMillis()
public long addTo(java.util.TimeZone timezone,
long timestamp)
timezone - The TimeZone of the event or null in case of a floating event.timestamp - The timestamp in milliseconds since the epoch.public java.lang.String toString()
toString in class java.lang.Objectpublic void writeTo(java.lang.StringBuilder builder)
StringBuilder.builder - A StringBuilder to write to.public void writeTo(java.io.Writer writer)
throws java.io.IOException
Writer.writer - A Writer to write to.java.io.IOExceptionpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Object