|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.deltax.util.TimeInterval
A class implementing a time interval, which parses back and forth human-readable specifications.
The minimum time unit is the minute: when converting from milliseconds, any part of minute is discarded, so for example a TimeInterval of 65.000ms equals a TimeInterval of 60.000ms.
The maximum time unit is the week.
The format for a string denoting a time interval is [w week[s]][+|,][ d day[s]][+|,][ h hour[s]][+|,][ m minutes[s]], where w,d ,h,m are integer values, and the following abbreviations may be used:
Normal | Compact | Single char | Fixed length |
week | wk | w | ww |
day | - | d | dd |
hour | hr | h | hh |
minute | min | m | mm |
For example, 1week+2days+3hrs+30min or 3hrs,30min are valid descriptors.
Field Summary | |
static long |
DAY
One day, in milliseconds |
static java.lang.String[] |
DAY_STR
Descriptions and abbreviations for day |
long |
days
Days portion of the time interval |
static long |
HOUR
One hour, in milliseconds |
static java.lang.String[] |
HOUR_STR
Descriptions and abbreviations for hour |
long |
hours
Hours portion of the time interval |
static long |
MILLISECOND
One millisecond |
static java.lang.String[] |
MILLISECOND_STR
Descriptions and abbreviations for millisecond |
long |
milliseconds
Milliseconds portion of the time interval |
static long |
MINUTE
One minute, in milliseconds |
static java.lang.String[] |
MINUTE_STR
Descriptions and abbreviations for minute |
long |
minutes
Minute portion of the time interval |
static long |
SECOND
One second |
static java.lang.String[] |
SECOND_STR
Descriptions and abbreviations for second |
long |
seconds
Seconds portion of the time interval |
static long |
WEEK
One week, in milliseconds |
static java.lang.String[] |
WEEK_STR
Descriptions and abbreviations for week |
long |
weeks
Week portion of the time interval |
Constructor Summary | |
TimeInterval()
Create a time interval of zero length |
|
TimeInterval(long l)
Create a time interval of the given length, in milliseconds |
|
TimeInterval(long weeks,
long days,
long hours,
long minutes,
long seconds,
long milliseconds)
Create a time interval, with the specified week/day/hour/minute values |
|
TimeInterval(java.lang.String s)
Creates a TimeInterval parsing a formatted specification. |
Method Summary | |
static java.lang.String |
describe(long interval)
Return the canonic description of the given interval (in milliseconds). |
boolean |
equals(java.lang.Object obj)
Return true only for a TimeInterval encapsulating the same amount of time, false otherwise. |
long |
getTime()
Return the length of this timeinterval, in milliseconds |
int |
hashCode()
Return the hash code for this time interval |
boolean |
longer(TimeInterval timeinterval)
Return true if the given time interval is longer than this |
static void |
main(java.lang.String[] args)
Attempts to parse the first argument and prints out its value in milliseconds. |
static TimeInterval |
parse(java.lang.String s)
Parses a time interval formatted description and returns the corresponding TimeInterval object See class comment for information on the format. |
boolean |
shorter(TimeInterval timeinterval)
Return true if the given time interval is shorter than this |
java.lang.String |
toString()
Create a formatted description of the timeinterval |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final long MILLISECOND
public static final long SECOND
public static final long MINUTE
public static final long HOUR
public static final long DAY
public static final long WEEK
public static final java.lang.String[] MILLISECOND_STR
public static final java.lang.String[] SECOND_STR
public static final java.lang.String[] MINUTE_STR
public static final java.lang.String[] HOUR_STR
public static final java.lang.String[] DAY_STR
public static final java.lang.String[] WEEK_STR
public long milliseconds
public long seconds
public long weeks
public long days
public long hours
public long minutes
Constructor Detail |
public TimeInterval()
public TimeInterval(long l)
l
- the length of the interval, in millisecondspublic TimeInterval(long weeks, long days, long hours, long minutes, long seconds, long milliseconds)
weeks
- the week portion of the time intervaldays
- the day portion of the time intervalhours
- the hour portion of the time intervalminutes
- the minute portion of the time intervalpublic TimeInterval(java.lang.String s) throws TimeIntervalFormatException
s
- the formatted string denoting the time intervalMethod Detail |
public long getTime()
public static TimeInterval parse(java.lang.String s) throws TimeIntervalFormatException
s
- the formatted string denoting the time interval
TimeIntervalFormatException
public static java.lang.String describe(long interval)
interval
- the interval to describe, in milliseconds
public boolean longer(TimeInterval timeinterval)
public boolean shorter(TimeInterval timeinterval)
public java.lang.String toString()
public boolean equals(java.lang.Object obj)
public int hashCode()
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |