public class TimeSpan extends Object implements Comparable<TimeSpan>
"(decimal[unit] |decimal )*"
.Time Unit | Unit symbol | Value in milliseconds | Examples |
---|---|---|---|
years | y or Y | 365.25*24*60*60*1000 | 2y, 2Y,1.3y |
months | M (casesensitive) | 31*24*60*60*1000 | 2M,3.4M |
weeks | w or W | 7*24*60*60*1000 | 2W,3w,5.4w |
days | d or D | 24*60*60*1000 | 14d,21D,12.34D |
hours | h or H | 60*60*1000 | 14h,21H,12.34h |
minutes | m (casesensitive) | 60*1000 | 14m,21m,12.34m |
seconds | s or S | 1000 | 14s,21S,12.34s |
milliseconds | (no symbol, default) | 1 | 1,3453,343.43 |
TimeSpanUnit
Modifier and Type | Field and Description |
---|---|
static TimeSpan |
DAYS_01
1 day
|
static TimeSpan |
DAYS_02
2 days
|
static TimeSpan |
DAYS_03
3 days
|
static TimeSpan |
DAYS_04
4 days
|
static TimeSpan |
DAYS_05
5 days
|
static TimeSpan |
DAYS_06
6 days
|
static TimeSpan |
DAYS_07
7 days
|
static TimeSpan |
DAYS_08
8 days
|
static TimeSpan |
DAYS_09
9 days
|
static TimeSpan |
DAYS_10
10 days
|
static TimeSpan |
DAYS_11
11 days
|
static TimeSpan |
DAYS_12
12 days
|
static TimeSpan |
DAYS_13
13 days
|
static TimeSpan |
DAYS_14
14 days
|
static TimeSpan |
DAYS_15
15 days
|
static TimeSpan |
DAYS_16
16 days
|
static TimeSpan |
DAYS_17
17 days
|
static TimeSpan |
DAYS_18
18 days
|
static TimeSpan |
DAYS_19
19 days
|
static TimeSpan |
DAYS_20
20 days
|
static TimeSpan |
DAYS_21
21 days
|
static TimeSpan |
DAYS_22
22 days
|
static TimeSpan |
DAYS_23
23 days
|
static TimeSpan |
DAYS_24
24 days
|
static TimeSpan |
DAYS_25
25 days
|
static TimeSpan |
DAYS_26
26 days
|
static TimeSpan |
DAYS_27
27 days
|
static TimeSpan |
DAYS_28
28 days
|
static TimeSpan |
DAYS_29
29 days
|
static TimeSpan |
DAYS_30
30 days
|
static TimeSpan |
DAYS_31
31 days
|
static TimeSpan |
HOURS_01
1 hour
|
static TimeSpan |
HOURS_02
2 hours
|
static TimeSpan |
HOURS_03
3 hours
|
static TimeSpan |
HOURS_04
4 hours
|
static TimeSpan |
HOURS_05
5 hours
|
static TimeSpan |
HOURS_06
6 hours
|
static TimeSpan |
HOURS_07
7 hours
|
static TimeSpan |
HOURS_08
8 hours
|
static TimeSpan |
HOURS_09
9 hours
|
static TimeSpan |
HOURS_10
10 hours
|
static TimeSpan |
HOURS_11
11 hours
|
static TimeSpan |
HOURS_12
12 hours
|
static TimeSpan |
HOURS_13
13 hours
|
static TimeSpan |
HOURS_14
14 hours
|
static TimeSpan |
HOURS_15
15 hours
|
static TimeSpan |
HOURS_16
16 hours
|
static TimeSpan |
HOURS_17
17 hours
|
static TimeSpan |
HOURS_18
18 hours
|
static TimeSpan |
HOURS_19
19 hours
|
static TimeSpan |
HOURS_20
20 hours
|
static TimeSpan |
HOURS_21
21 hours
|
static TimeSpan |
HOURS_22
22 hours
|
static TimeSpan |
HOURS_23
23 hours
|
static TimeSpan |
HOURS_24
24 hours
|
static TimeSpan |
MINUTES_01
1 minut
|
static TimeSpan |
MINUTES_02
2 minutes
|
static TimeSpan |
MINUTES_03
3 minutes
|
static TimeSpan |
MINUTES_04
4 minutes
|
static TimeSpan |
MINUTES_05
5 minutes
|
static TimeSpan |
MINUTES_10
10 minutes
|
static TimeSpan |
MINUTES_15
15 minutes
|
static TimeSpan |
MINUTES_20
20 minutes
|
static TimeSpan |
MINUTES_25
25 minutes
|
static TimeSpan |
MINUTES_30
30 minutes
|
static TimeSpan |
MINUTES_35
35 minutes
|
static TimeSpan |
MINUTES_40
40 minutes
|
static TimeSpan |
MINUTES_45
45 minutes
|
static TimeSpan |
MINUTES_50
50 minutes
|
static TimeSpan |
MINUTES_55
55 minutes
|
static TimeSpan |
MINUTES_60
60 minutes
|
static TimeSpan |
MONTHS_1
1 month - 31 days
|
static TimeSpan |
MONTHS_12
12 months - 12x 31 days
|
static TimeSpan |
MONTHS_2
2 months - 2x 31 days
|
static TimeSpan |
MONTHS_3
3 months - 3x 31 days
|
static TimeSpan |
MONTHS_6
6 months - 6x 31 days
|
static TimeSpan |
MONTHS_9
9 months - 9x 31 days
|
static TimeSpan |
SECONDS_01
1 second
|
static TimeSpan |
SECONDS_15
15 seconds
|
static TimeSpan |
SECONDS_30
30 seconds
|
static TimeSpan |
SECONDS_45
45 seconds
|
static TimeSpan |
SECONDS_60
60seconds
|
static long |
UNIT_TIME_DAY |
static long |
UNIT_TIME_HOUR |
static long |
UNIT_TIME_MILLISECOND |
static long |
UNIT_TIME_MINUTE |
static long |
UNIT_TIME_MONTH |
static long |
UNIT_TIME_SECOND |
static long |
UNIT_TIME_WEEK |
static long |
UNIT_TIME_YEAR |
static TimeSpan |
WEEKS_1
1 week - 7 days
|
static TimeSpan |
WEEKS_2
2 weeks - 14 days
|
static TimeSpan |
WEEKS_3
3 weeks - 21 days
|
static TimeSpan |
WEEKS_4
4 weeks - 28 days
|
static TimeSpan |
YEARS_1
1 year - 365 days
|
static TimeSpan |
YEARS_10
10 years - 10x 365 days
|
static TimeSpan |
YEARS_100
100 years - 100x 365 days
|
static TimeSpan |
YEARS_2
2 years - 2x 365 days
|
static TimeSpan |
YEARS_25
25 years - 25x 365 days
|
static TimeSpan |
YEARS_3
3 years - 3x 365 days
|
static TimeSpan |
YEARS_5
5 years - 5x 365 days
|
static TimeSpan |
YEARS_50
50 years - 50x 365 days
|
static TimeSpan |
ZERO
0 time
|
Constructor and Description |
---|
TimeSpan(int years,
long months,
long weeks,
long days,
long hours,
long minutes,
long seconds,
long milliseconds)
Constructor using individual unit values, a name will be generated using the getParsableText() method.
|
TimeSpan(long span)
Constructor, a name will be generated using the getParsableText() method.
|
TimeSpan(String name,
long span)
Constructor.
|
TimeSpan(String name,
long years,
long months,
long weeks,
long days,
long hours,
long minutes,
long seconds,
long milliseconds)
Constructor using individual unit values.
|
Modifier and Type | Method and Description |
---|---|
TimeSpan |
add(long milliseconds)
Adds a milliseconds value to the current TimeSpan in a new TimeSpan instance.
|
TimeSpan |
add(TimeSpan value)
Adds a TimeSpan value to the current TimeSpan in a new TimeSpan instance.
|
TimeSpan |
add(TimeSpan value,
int factor)
Adds a TimeSpan value, which is multiplied with a factor, to the current TimeSpan in a new TimeSpan instance.
|
int |
compareTo(TimeSpan o)
Compares this TimeSpan with another on the "getSpan()"
|
static TimeSpan |
diff(TimeSpan t1,
TimeSpan t2)
The Math.abs() differences between two timespans.
|
long |
dueIn(Date from)
The number of milleseconds before a timespan is due for a date and NOW
|
long |
dueIn(Date from,
Date to)
The number of milleseconds before a timespan is due for two dates
|
boolean |
equals(Object obj)
If the millisecond span "getSpan" is equal.
|
String |
getCaption()
Creates a readable text caption for the Timespan.
|
long |
getDays()
How many days the timespan covers, minus all the rest.
|
static TimeSpan |
getDays(int days)
Generates a Timespan of X days.
|
long |
getHours()
How many hours the timespan covers, minus all the rest.
|
static TimeSpan |
getHours(int hours)
Generates a Timespan of X hours.
|
long |
getMilliseconds()
How many milliseconds the timespan covers, minus all the rest.
|
static TimeSpan |
getMilliSeconds(int milliSeconds)
Generates a Timespan of X years.
|
long |
getMinutes()
How many minutes the timespan covers, minus all the rest.
|
static TimeSpan |
getMinutes(int minutes)
Generates a Timespan of X minutes.
|
static TimeSpan |
getMonths(int months)
Generates a Timespan of X months.
|
String |
getName()
The TimeSpan name
|
String |
getParsableText()
Using the "milliseconds, seconds, minutes, hours, days, years" values constructing a value which can be parsed by
TimeSpan.parse(String) . |
long |
getSeconds()
How many seconds the timespan covers, minus all the rest.
|
static TimeSpan |
getSeconds(int seconds)
Generates a Timespan of X years.
|
long |
getSpan()
The primary value, from which all other values eminates.
|
static TimeSpan |
getWeeks(int weeks)
Generates a Timespan of X weeks.
|
long |
getYears()
How many years the timespan covers, minus all the rest.
|
static TimeSpan |
getYears(int years)
Generates a Timespan of X years.
|
int |
hashCode()
The hashCode of the toString method.
|
boolean |
isGreatherThan(TimeSpan other)
Compares this with another TimeSpan, and determines if this is less than other.
|
boolean |
isLessThan(TimeSpan other)
Compares this with another TimeSpan, and determines if this is greather than other.
|
boolean |
isPastSpan(Date from)
Is the difference of a date and NOW larger than the timespan.
|
boolean |
isPastSpan(Date from,
Date to)
Is the difference of two dates larger than the timespan.
|
TimeSpan |
multiply(double factor)
Multiplies the current Timespan with a double factor in a new TimeSpan instance.
|
static TimeSpan |
parse(Date from)
Constructs a TimeSpan instance on the basis of the difference between a date and the NOW date.
|
static TimeSpan |
parse(Date from,
Date to)
Constructs a TimeSpan instance on the basis of the difference between to date instances.
|
static TimeSpan |
parse(String textValue)
Concstructs a TimeSpan instance of the basis string value parsing.
|
TimeSpan |
substract(long milliseconds)
Subtracts a milliseconds value to the current TimeSpan in a new TimeSpan instance.
|
TimeSpan |
substract(TimeSpan value)
Subtracts a TimeSpan value to the current in a new TimeSpan instance.
|
TimeSpan |
substract(TimeSpan value,
int factor)
Subtracts a TimeSpan value, which is mulitiplied with a factor, to the current TimeSpan in a new TimeSpan instance.
|
long |
toMilliseconds()
Gets the timespan as milliseconds, the same as "getSpan()".
|
String |
toString()
Returns the getParsableText() value.
|
public static final long UNIT_TIME_MILLISECOND
TimeSpanUnit.ms
public static final long UNIT_TIME_SECOND
TimeSpanUnit.S
public static final long UNIT_TIME_MINUTE
TimeSpanUnit.m
public static final long UNIT_TIME_HOUR
TimeSpanUnit.H
public static final long UNIT_TIME_DAY
TimeSpanUnit.D
public static final long UNIT_TIME_WEEK
TimeSpanUnit.W
public static final long UNIT_TIME_MONTH
TimeSpanUnit.M
public static final long UNIT_TIME_YEAR
TimeSpanUnit.Y
public static final TimeSpan ZERO
public static final TimeSpan SECONDS_01
public static final TimeSpan SECONDS_15
public static final TimeSpan SECONDS_30
public static final TimeSpan SECONDS_45
public static final TimeSpan SECONDS_60
public static final TimeSpan MINUTES_01
public static final TimeSpan MINUTES_02
public static final TimeSpan MINUTES_03
public static final TimeSpan MINUTES_04
public static final TimeSpan MINUTES_05
public static final TimeSpan MINUTES_10
public static final TimeSpan MINUTES_15
public static final TimeSpan MINUTES_20
public static final TimeSpan MINUTES_25
public static final TimeSpan MINUTES_30
public static final TimeSpan MINUTES_35
public static final TimeSpan MINUTES_40
public static final TimeSpan MINUTES_45
public static final TimeSpan MINUTES_50
public static final TimeSpan MINUTES_55
public static final TimeSpan MINUTES_60
public static final TimeSpan HOURS_01
public static final TimeSpan HOURS_02
public static final TimeSpan HOURS_03
public static final TimeSpan HOURS_04
public static final TimeSpan HOURS_05
public static final TimeSpan HOURS_06
public static final TimeSpan HOURS_07
public static final TimeSpan HOURS_08
public static final TimeSpan HOURS_09
public static final TimeSpan HOURS_10
public static final TimeSpan HOURS_11
public static final TimeSpan HOURS_12
public static final TimeSpan HOURS_13
public static final TimeSpan HOURS_14
public static TimeSpan HOURS_15
public static final TimeSpan HOURS_16
public static final TimeSpan HOURS_17
public static final TimeSpan HOURS_18
public static final TimeSpan HOURS_19
public static final TimeSpan HOURS_20
public static final TimeSpan HOURS_21
public static final TimeSpan HOURS_22
public static final TimeSpan HOURS_23
public static final TimeSpan HOURS_24
public static final TimeSpan DAYS_01
public static final TimeSpan DAYS_02
public static final TimeSpan DAYS_03
public static final TimeSpan DAYS_04
public static final TimeSpan DAYS_05
public static final TimeSpan DAYS_06
public static final TimeSpan DAYS_07
public static final TimeSpan DAYS_08
public static final TimeSpan DAYS_09
public static final TimeSpan DAYS_10
public static final TimeSpan DAYS_11
public static final TimeSpan DAYS_12
public static final TimeSpan DAYS_13
public static final TimeSpan DAYS_14
public static final TimeSpan DAYS_15
public static final TimeSpan DAYS_16
public static final TimeSpan DAYS_17
public static TimeSpan DAYS_18
public static final TimeSpan DAYS_19
public static final TimeSpan DAYS_20
public static final TimeSpan DAYS_21
public static final TimeSpan DAYS_22
public static final TimeSpan DAYS_23
public static final TimeSpan DAYS_24
public static final TimeSpan DAYS_25
public static final TimeSpan DAYS_26
public static final TimeSpan DAYS_27
public static final TimeSpan DAYS_28
public static final TimeSpan DAYS_29
public static final TimeSpan DAYS_30
public static final TimeSpan DAYS_31
public static final TimeSpan WEEKS_1
public static final TimeSpan WEEKS_2
public static final TimeSpan WEEKS_3
public static final TimeSpan WEEKS_4
public static final TimeSpan MONTHS_1
public static final TimeSpan MONTHS_2
public static final TimeSpan MONTHS_3
public static final TimeSpan MONTHS_6
public static final TimeSpan MONTHS_9
public static final TimeSpan MONTHS_12
public static final TimeSpan YEARS_1
public static final TimeSpan YEARS_2
public static final TimeSpan YEARS_3
public static final TimeSpan YEARS_5
public static final TimeSpan YEARS_10
public static final TimeSpan YEARS_25
public static final TimeSpan YEARS_50
public static final TimeSpan YEARS_100
public TimeSpan(long span) throws IllegalArgumentException
span
- the timespan in milliseconds.IllegalArgumentException
- if span is less than zero.getParsableText()
public TimeSpan(String name, long span) throws IllegalArgumentException
name
- the name of the timespan.span
- the timespan in milliseconds.IllegalArgumentException
- if span is less than zero.public TimeSpan(String name, long years, long months, long weeks, long days, long hours, long minutes, long seconds, long milliseconds)
name
- the name of the timespan.years
- the number of years. If less or equal to zero, the value is ignored.months
- the number of months, will be converted to days, by multiplying by 31. If less or equal to zero, the value is ignored.weeks
- the number of weeks, will be converted to days, by multiplying by 7. If less or equal to zero, the value is ignored.days
- the number of days. If less or equal to zero, the value is ignored.hours
- the number of hours. If less or equal to zero, the value is ignored.minutes
- the number of minutes. If less or equal to zero, the value is ignored.seconds
- the number of seconds. If less or equal to zero, the value is ignored.milliseconds
- the number of milliseconds. If less or equal to zero, the value is ignored.public TimeSpan(int years, long months, long weeks, long days, long hours, long minutes, long seconds, long milliseconds)
years
- the number of years. If less or equal to zero, the value is ignored.months
- the number of months, will be converted to days, by multiplying by 31. If less or equal to zero, the value is ignored.weeks
- the number of weeks, will be converted to days, by multiplying by 7. If less or equal to zero, the value is ignored.days
- the number of days. If less or equal to zero, the value is ignored.hours
- the number of hours. If less or equal to zero, the value is ignored.minutes
- the number of minutes. If less or equal to zero, the value is ignored.seconds
- the number of seconds. If less or equal to zero, the value is ignored.milliseconds
- the number of milliseconds. If less or equal to zero, the value is ignored.getParsableText()
public static final TimeSpan getYears(int years) throws IllegalArgumentException
years
- the number of yearsIllegalArgumentException
- if years is less than zero.add(TimeSpan)
,
substract(TimeSpan)
public static final TimeSpan getMonths(int months) throws IllegalArgumentException
months
- the number of monthsIllegalArgumentException
- if months is less than zero.add(TimeSpan)
,
substract(TimeSpan)
public static final TimeSpan getWeeks(int weeks) throws IllegalArgumentException
weeks
- the number of weeksIllegalArgumentException
- if weeks is less than zero.add(TimeSpan)
,
substract(TimeSpan)
public static final TimeSpan getDays(int days) throws IllegalArgumentException
days
- the number of daysIllegalArgumentException
- if days is less than zero.add(TimeSpan)
,
substract(TimeSpan)
public static final TimeSpan getHours(int hours) throws IllegalArgumentException
hours
- the number of hoursIllegalArgumentException
- if hours is less than zero.add(TimeSpan)
,
substract(TimeSpan)
public static final TimeSpan getMinutes(int minutes) throws IllegalArgumentException
minutes
- the number of minutesIllegalArgumentException
- if minutes is less than zero.add(TimeSpan)
,
substract(TimeSpan)
public static final TimeSpan getSeconds(int seconds) throws IllegalArgumentException
seconds
- the number of secondsIllegalArgumentException
- if seconds is less than zero.add(TimeSpan)
,
substract(TimeSpan)
public static final TimeSpan getMilliSeconds(int milliSeconds) throws IllegalArgumentException
milliSeconds
- the number of milliSecondsIllegalArgumentException
- if milliSeconds is less than zero.add(TimeSpan)
,
substract(TimeSpan)
public static final TimeSpan parse(String textValue) throws Exception
textValue
- the string value using the TimeSpan text format convention.PropertyException
- if for any reason the string value is invalid or unparseable.Exception
public static final TimeSpan parse(Date from, Date to) throws Exception
from
- the from date.to
- the to date.PropertyException
- if either dates is null
.Exception
public static final TimeSpan parse(Date from) throws Exception
from
- the from datePropertyException
- if from date is null
.Exception
public static final TimeSpan diff(TimeSpan t1, TimeSpan t2) throws NullPointerException
t1
- a timeSpant2
- a timeSpannew TimeSpan(Math.abs(o1.getSpan()-o2.getSpan()))
.NullPointerException
- if either t1 or t2 is null
.public TimeSpan add(TimeSpan value) throws IllegalArgumentException, NullPointerException
value
- the Timespan valueIllegalArgumentException
- if the new value is less than zero.NullPointerException
- if the TimeSpan value is null
.public TimeSpan substract(TimeSpan value) throws IllegalArgumentException, NullPointerException
value
- the Timespan valueIllegalArgumentException
- if the new value is less than zero.NullPointerException
- if the TimeSpan value is null
.public TimeSpan add(TimeSpan value, int factor) throws IllegalArgumentException, NullPointerException
value
- the Timespan valuefactor
- the factor which the TimeSpan value will be multipliedIllegalArgumentException
- if the new value is less than zero.NullPointerException
- if the TimeSpan value is null
.public TimeSpan substract(TimeSpan value, int factor) throws IllegalArgumentException, NullPointerException
value
- the Timespan valuefactor
- the factor which the TimeSpan value will be multipliedIllegalArgumentException
- if the new value is less than zero.NullPointerException
- if the TimeSpan value is null
.public TimeSpan add(long milliseconds) throws IllegalArgumentException
milliseconds
- a value in milliseconds.IllegalArgumentException
- if the new value is less than zero.public TimeSpan substract(long milliseconds) throws IllegalArgumentException
milliseconds
- a value in milliseconds.IllegalArgumentException
- if the new value is less than zero.public TimeSpan multiply(double factor) throws IllegalArgumentException
factor
- the factor to multiply with, has to greather than zero.IllegalArgumentException
- if factor is less or equal to zero.public String getParsableText()
TimeSpan.parse(String)
.parse(String)
public String toString()
public int hashCode()
public boolean equals(Object obj)
public int compareTo(TimeSpan o)
compareTo
in interface Comparable<TimeSpan>
public String getName()
public long getSpan()
public long getYears()
public long getDays()
public long getHours()
public long getMinutes()
public long getSeconds()
public long getMilliseconds()
public String getCaption()
public boolean isPastSpan(Date from, Date to)
from
- the from dateto
- the to datenull
then false
is returned, otherwise true
of the milliseconds difference between to and from is greather than the timespan; else false
.public boolean isPastSpan(Date from)
from
- the from datenull
then false
is returned, otherwise true
of the milliseconds difference between NOW and from is greather than the timespan; else false
.public long dueIn(Date from, Date to)
from
- the from dateto
- the to datenull
then 0
is returned, otherwise the timespan in milliseconds minus the difference of the two dates. If negative than it is past due time.public long dueIn(Date from)
from
- the from datenull
then 0
is returned, otherwise the timespan in milliseconds minus the difference of the date and NOW. If negative than it is past due time.public boolean isLessThan(TimeSpan other) throws NullPointerException
other
- another instance of TimeSpan.true
if this is less than other, otherwise false
.NullPointerException
- if other is null
.public boolean isGreatherThan(TimeSpan other) throws NullPointerException
other
- another instance of TimeSpan.true
if this is greather than other, otherwise false
.NullPointerException
- if other is null
.public final long toMilliseconds()
getSpan()
Copyright © 2016. All rights reserved.