|
|
|
|
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.torweg.pulse.util.time.TimeSpan
@Embeddable public final class TimeSpan
represents a time span in human readable format.
Numbers directly followed by the character y are interpreted as years. The character d represents days, h represents hours, m represents minutes and s represents seconds. If a number is followed by a space or is at the end of the time span string, it is interpreted as milliseconds.
Examples:
1y 2m 11s represents a time span of one year, two minutes and 11
seconds.
1234567 represents a time span of 1234567 milliseconds, or 20
minutes, 34 seconds and 567 milliseconds
2d represents a time span of two days.
2m -30s represents 90 seconds.
| Nested Class Summary | |
|---|---|
static class |
TimeSpan.TimeConstant
the time constants. |
| Constructor Summary | |
|---|---|
protected |
TimeSpan()
Deprecated. |
|
TimeSpan(long millis)
creates a new TimeSpan with the given amount of milliseconds. |
|
TimeSpan(java.lang.String ts)
creates a new TimeSpan from the given time string. |
|
TimeSpan(TimeSpan source)
creates a new TimeSpan from the given TimeSpan. |
| Method Summary | |
|---|---|
TimeSpan |
add(long millis)
adds the given milliseconds to this time span. |
TimeSpan |
add(TimeSpan s)
adds a given time span to this time span. |
java.util.Date |
addTo(java.util.Date d)
returns a new Date with the time span added to the Date. |
int |
compareTo(TimeSpan o)
compare the two time spans. |
boolean |
equals(java.lang.Object obj)
checks whether the given object is equal to the time span. |
long |
getMilliseconds()
returns the milliseconds. |
java.lang.String |
getSpan()
returns the string value. |
int |
hashCode()
returns a hash code for this instance. |
static long |
millisFromString(java.lang.String ts)
parses the time string to a time span in milliseconds. |
void |
setMilliseconds(long ms)
sets the milliseconds for the time span. |
void |
setSpan(java.lang.String s)
sets the value. |
static java.lang.String |
stringFromMillis(long m)
returns a time string for the given value in milliseconds. |
TimeSpan |
subtract(TimeSpan s)
subtracts a given time span from this time span. |
java.util.Date |
subtractFrom(java.util.Date d)
returns a new Date with the time span subtracted from the Date. |
java.lang.String |
toString()
returns a string representation of the time span. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
@Deprecated protected TimeSpan()
public TimeSpan(java.lang.String ts)
TimeSpan from the given time string.
ts - the time stringpublic TimeSpan(long millis)
TimeSpan with the given amount of milliseconds.
millis - the millisecondspublic TimeSpan(TimeSpan source)
TimeSpan from the given TimeSpan.
source - the source time span| Method Detail |
|---|
public static long millisFromString(java.lang.String ts)
ts - the time string
stringFromMillis(long)public static java.lang.String stringFromMillis(long m)
m - the TimeSpan in milliseconds
millisFromString(String)public long getMilliseconds()
public void setMilliseconds(long ms)
ms - the time spanpublic java.lang.String getSpan()
public void setSpan(java.lang.String s)
s - the time span stringpublic TimeSpan add(TimeSpan s)
s - the time span to add
public TimeSpan add(long millis)
millis - the milliseconds to add
public TimeSpan subtract(TimeSpan s)
s - the time span to add
public java.util.Date addTo(java.util.Date d)
Date with the time span added to the Date.
d - the date
public java.util.Date subtractFrom(java.util.Date d)
Date with the time span subtracted from the Date.
d - the date
public java.lang.String toString()
toString in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.ObjectObject.hashCode()public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - the object
true, if and only if the two time spans are equal in
millisecondsObject.equals(java.lang.Object)public int compareTo(TimeSpan o)
compareTo in interface java.lang.Comparable<TimeSpan>o - the time span to compare with
Comparable.compareTo(java.lang.Object)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||