Package eu.woolplatform.utils.schedule
Class DateDuration
- java.lang.Object
-
- eu.woolplatform.utils.schedule.DateDuration
-
public class DateDuration extends Object
This class specifies a duration that spans one or more days. It consists of a number and a date unit. For example: 5 days or 3 months.
-
-
Constructor Summary
Constructors Constructor Description DateDuration(int count, DateUnit unit)Constructs a new date duration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)intgetCount()Returns the number of date units that defines this duration.intgetCountBetween(org.joda.time.ReadableInstant start, org.joda.time.ReadableInstant end)Returns the number of times this date duration completely fits between the two specified times.intgetCountBetween(org.joda.time.ReadablePartial start, org.joda.time.ReadablePartial end)Returns the number of times this date duration completely fits between the two specified times.DateUnitgetUnit()Returns the date unit that, together with the number returned bygetCount(), defines this duration.inthashCode()static DateDurationparse(String s, DateUnit min, DateUnit max)Parses a date duration from a string.org.joda.time.ReadablePeriodtoReadablePeriod()Returns this date duration as aReadablePeriod.StringtoString()
-
-
-
Constructor Detail
-
DateDuration
public DateDuration(int count, DateUnit unit)Constructs a new date duration.- Parameters:
count- the number of date unitsunit- the date unit
-
-
Method Detail
-
getCount
public int getCount()
Returns the number of date units that defines this duration. The date unit is obtained withgetUnit().- Returns:
- the number of date units
-
getUnit
public DateUnit getUnit()
Returns the date unit that, together with the number returned bygetCount(), defines this duration.- Returns:
- the date unit
-
getCountBetween
public int getCountBetween(org.joda.time.ReadableInstant start, org.joda.time.ReadableInstant end)Returns the number of times this date duration completely fits between the two specified times.- Parameters:
start- the start timeend- the end time- Returns:
- the number of durations between the start and end time
-
getCountBetween
public int getCountBetween(org.joda.time.ReadablePartial start, org.joda.time.ReadablePartial end)Returns the number of times this date duration completely fits between the two specified times.- Parameters:
start- the start timeend- the end time- Returns:
- the number of durations between the start and end time
-
toReadablePeriod
public org.joda.time.ReadablePeriod toReadablePeriod()
Returns this date duration as aReadablePeriod.- Returns:
- the readable period
-
parse
public static DateDuration parse(String s, DateUnit min, DateUnit max) throws ParseException
Parses a date duration from a string. The string should consist of a number and a date unit, separated by white space. You can specify the smallest and largest allowed date unit.- Parameters:
s- the stringmin- the smallest allowed date unit. You can set this to null for the smallest known date unit.max- the largest allowed date unit. You can set this to null for the largest known date unit.- Returns:
- the date duration
- Throws:
ParseException- if the string is invalid
-
-