Package oracle.rules.rl.extensions
Class Duration
java.lang.Object
oracle.rules.rl.extensions.Duration
- Direct Known Subclasses:
OracleDuration
RL Duration supports xml schema yearMonthDuration or dayTimeDuration.
You cannot mix yearMonthDuration and dayTimeDuration. Doing so may result in
IllegalStateException
RL Duration also supports static methods for getting the duration as numbers of
hours, days, etc. between 2 calendars (avoiding Duration objects).-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DurationCompute XML dayTimeDuration between 2 dates.static Durationbetween(Calendar date1, XMLGregorianCalendar date2) Compute XML dayTimeDuration between 2 dates.static Durationbetween(XMLGregorianCalendar date1, Calendar date2) Compute XML dayTimeDuration between 2 dates.static Durationbetween(XMLGregorianCalendar date1, XMLGregorianCalendar date2) Compute XML dayTimeDuration between 2 dates.static intCompares two dates and returns an int value of 0 if they are equal, less than 0 if date1 represents a point in time before date2, greater than 0 if date1 represents a point in time after date2.static intcompare(Calendar date1, XMLGregorianCalendar date2) Compares two dates and returns an int value of 0 if they are equal, less than 0 if date1 represents a point in time before date2, greater than 0 if date1 represents a point in time after date2.static intcompare(XMLGregorianCalendar date1, Calendar date2) Compares two dates and returns an int value of 0 if they are equal, less than 0 if date1 represents a point in time before date2, greater than 0 if date1 represents a point in time after date2.static intcompare(XMLGregorianCalendar date1, XMLGregorianCalendar date2) Compares two dates and returns an int value of 0 if they are equal, less than 0 if date1 represents a point in time before date2, greater than 0 if date1 represents a point in time after date2.static intcompareDurations(Duration duration1, Duration duration2) compare 2 XML durations.static intdaysBetween(Calendar date1, Calendar date2) static intdaysBetween(Calendar date1, XMLGregorianCalendar date2) Returns the difference between the two dates in days.static intdaysBetween(XMLGregorianCalendar date1, Calendar date2) Returns the difference between the two dates in days.static intdaysBetween(XMLGregorianCalendar date1, XMLGregorianCalendar date2) Returns the difference between the two dates in days.static DurationDivide the given duration by a numberstatic DurationDivide the given duration by a numberstatic DurationfromString(String lexicalRepresentation) create an XML Duration from its lexical representation, e.g.static BigDecimalgetSeconds(Duration xmlDuration) Get the seconds from the duration as a BigDecimal.static longhoursBetween(Calendar date1, Calendar date2) Returns the difference between the two dates in hours.static longhoursBetween(Calendar date1, XMLGregorianCalendar date2) Returns the difference between the two dates in hours.static longhoursBetween(XMLGregorianCalendar date1, Calendar date2) Returns the difference between the two dates in hours.static longhoursBetween(XMLGregorianCalendar date1, XMLGregorianCalendar date2) Returns the difference between the two dates in hours.static booleanisDayTimeDuration(Duration xmlDuration) is the xml duration a dayTimeDuration?static booleanisYearMonthDuration(Duration xmlDuration) is the xml duration a yearMonthDuration?static longmillisecondsBetween(Calendar date1, Calendar date2) Returns the difference between the two dates in milliseconds.static longmillisecondsBetween(Calendar date1, XMLGregorianCalendar date2) Returns the difference between the two dates in milliseconds.static longmillisecondsBetween(XMLGregorianCalendar date1, Calendar date2) Returns the difference between the two dates in milliseconds.static longmillisecondsBetween(XMLGregorianCalendar date1, XMLGregorianCalendar date2) Returns the difference between the two dates in milliseconds.static longminutesBetween(Calendar date1, Calendar date2) Returns the difference between the two dates in minutes.static longminutesBetween(Calendar date1, XMLGregorianCalendar date2) Returns the difference between the two dates in minutes.static longminutesBetween(XMLGregorianCalendar date1, Calendar date2) Returns the difference between the two dates in minutes.static longminutesBetween(XMLGregorianCalendar date1, XMLGregorianCalendar date2) Returns the difference between the two dates in minutes.static intmonthsBetween(Calendar date1, Calendar date2) Returns the difference between the two dates in months.static intmonthsBetween(Calendar date1, XMLGregorianCalendar date2) Returns the difference between the two dates in months.static intmonthsBetween(XMLGregorianCalendar date1, Calendar date2) Returns the difference between the two dates in months.static intmonthsBetween(XMLGregorianCalendar date1, XMLGregorianCalendar date2) Returns the difference between the two dates in months.static DurationMultiply the given duration by a numberstatic Durationmultiply(Duration duration, BigDecimal factor) Multiply the given duration by a numberstatic BigDecimalDivide the first duration by the second durationstatic longsecondsBetween(Calendar date1, Calendar date2) Returns the difference between the two dates in seconds.static longsecondsBetween(Calendar date1, XMLGregorianCalendar date2) Returns the difference between the two dates in seconds.static longsecondsBetween(XMLGregorianCalendar date1, Calendar date2) Returns the difference between the two dates in seconds.static longsecondsBetween(XMLGregorianCalendar date1, XMLGregorianCalendar date2) Returns the difference between the two dates in seconds.static intweeksBetween(Calendar date1, Calendar date2) Returns the difference between the two dates in weeks.static intweeksBetween(Calendar date1, XMLGregorianCalendar date2) Returns the difference between the two dates in weeks.static intweeksBetween(XMLGregorianCalendar date1, Calendar date2) Returns the difference between the two dates in weeks.static intweeksBetween(XMLGregorianCalendar date1, XMLGregorianCalendar date2) Returns the difference between the two dates in weeks.static intyearsBetween(Calendar date1, Calendar date2) Returns the difference between the two dates in years.static intyearsBetween(Calendar date1, XMLGregorianCalendar date2) Returns the difference between the two dates in years.static intyearsBetween(XMLGregorianCalendar date1, Calendar date2) Returns the difference between the two dates in years.static intyearsBetween(XMLGregorianCalendar date1, XMLGregorianCalendar date2) Returns the difference between the two dates in years.
-
Constructor Details
-
Duration
public Duration()
-
-
Method Details
-
yearsBetween
Returns the difference between the two dates in years. The difference may be negative if date1 is later than date2. Any resulting fractional year is truncated.date1anddate2are converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of years between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
yearsBetween
Returns the difference between the two dates in years. The difference may be negative if date1 is later than date2. Any resulting fractional year is truncated.- Parameters:
date1-date2-- Returns:
- the number of years between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
yearsBetween
Returns the difference between the two dates in years. The difference may be negative if date1 is later than date2. Any resulting fractional year is truncated.date1is converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of years between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
yearsBetween
Returns the difference between the two dates in years. The difference may be negative if date1 is later than date2. Any resulting fractional year is truncated.date2is converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of years between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
monthsBetween
Returns the difference between the two dates in months. The difference may be negative if date1 is later than date2. Any resulting fractional month is truncated.date1is converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of months between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
monthsBetween
Returns the difference between the two dates in months. The difference may be negative if date1 is later than date2. Any resulting fractional month is truncated.- Parameters:
date1-date2-- Returns:
- the number of months between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
monthsBetween
Returns the difference between the two dates in months. The difference may be negative if date1 is later than date2. Any resulting fractional month is truncated.date1anddate2are converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of months between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
monthsBetween
Returns the difference between the two dates in months. The difference may be negative if date1 is later than date2. Any resulting fractional month is truncated.date2is converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of months between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
weeksBetween
Returns the difference between the two dates in weeks. The difference may be negative if date1 is later than date2. Any resulting fractional week is truncated.date1anddate2are converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of weeks between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
weeksBetween
Returns the difference between the two dates in weeks. The difference may be negative if date1 is later than date2. Any resulting fractional week is truncated.- Parameters:
date1-date2-- Returns:
- the number of weeks between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
weeksBetween
Returns the difference between the two dates in weeks. The difference may be negative if date1 is later than date2. Any resulting fractional week is truncated.date1is converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of weeks between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
weeksBetween
Returns the difference between the two dates in weeks. The difference may be negative if date1 is later than date2. Any resulting fractional week is truncated.date2is converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of weeks between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
daysBetween
-
hoursBetween
Returns the difference between the two dates in hours. The difference may be negative if date1 is later than date2. Any resulting fractional hour is truncated.date1anddate2are converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of hours between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
hoursBetween
Returns the difference between the two dates in hours. The difference may be negative if date1 is later than date2. Any resulting fractional hour is truncated.- Parameters:
date1-date2-- Returns:
- the number of hours between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
daysBetween
Returns the difference between the two dates in days. The difference may be negative if date1 is later than date2. Any resulting fractional day is truncated.date1anddate2are converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of days between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
daysBetween
Returns the difference between the two dates in days. The difference may be negative if date1 is later than date2. Any resulting fractional day is truncated.date1is converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of days between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
daysBetween
Returns the difference between the two dates in days. The difference may be negative if date1 is later than date2. Any resulting fractional day is truncated.date2is converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of days between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
hoursBetween
Returns the difference between the two dates in hours. The difference may be negative if date1 is later than date2. Any resulting fractional hour is truncated.date1is converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of hours between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
hoursBetween
Returns the difference between the two dates in hours. The difference may be negative if date1 is later than date2. Any resulting fractional hour is truncated.date2is converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of hours between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
minutesBetween
Returns the difference between the two dates in minutes. The difference may be negative if date1 is later than date2. Any resulting fractional minute is truncated.- Parameters:
date1-date2-- Returns:
- the number of minutes between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
minutesBetween
Returns the difference between the two dates in minutes. The difference may be negative if date1 is later than date2. Any resulting fractional minute is truncated.date1anddate2are converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of minutes between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
minutesBetween
Returns the difference between the two dates in minutes. The difference may be negative if date1 is later than date2. Any resulting fractional minute is truncated.date1is converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of minutes between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
minutesBetween
Returns the difference between the two dates in minutes. The difference may be negative if date1 is later than date2. Any resulting fractional minute is truncated.date2is converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of minutes between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
secondsBetween
Returns the difference between the two dates in seconds. The difference may be negative if date1 is later than date2. Any resulting fractional second is truncated.date1anddate2are converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of seconds between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
secondsBetween
Returns the difference between the two dates in seconds. The difference may be negative if date1 is later than date2. Any resulting fractional second is truncated.- Parameters:
date1-date2-- Returns:
- the number of seconds between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
secondsBetween
Returns the difference between the two dates in seconds. The difference may be negative if date1 is later than date2. Any resulting fractional second is truncated.date1is converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of seconds between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
secondsBetween
Returns the difference between the two dates in seconds. The difference may be negative if date1 is later than date2. Any resulting fractional second is truncated.date2is converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of seconds between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
millisecondsBetween
Returns the difference between the two dates in milliseconds. The difference may be negative if date1 is later than date2.date1anddate2are converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of milliseconds between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
millisecondsBetween
Returns the difference between the two dates in milliseconds. The difference may be negative if date1 is later than date2.- Parameters:
date1-date2-- Returns:
- the number of milliseconds between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
millisecondsBetween
Returns the difference between the two dates in milliseconds. The difference may be negative if date1 is later than date2.date1is converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of milliseconds between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
millisecondsBetween
Returns the difference between the two dates in milliseconds. The difference may be negative if date1 is later than date2.date2is converted toGregorianCalendarbefore the difference is calculated.- Parameters:
date1-date2-- Returns:
- the number of milliseconds between the date1 and date2.
- Throws:
NullPointerException- if either date1 or date2 is null.
-
compare
Compares two dates and returns an int value- of 0 if they are equal,
- less than 0 if date1 represents a point in time before date2,
- greater than 0 if date1 represents a point in time after date2.
- Parameters:
date1-date2-- Returns:
- the relative comparison result.
-
compare
Compares two dates and returns an int value- of 0 if they are equal,
- less than 0 if date1 represents a point in time before date2,
- greater than 0 if date1 represents a point in time after date2.
- Parameters:
date1-date2-- Returns:
- the relative comparison result.
-
compare
Compares two dates and returns an int value- of 0 if they are equal,
- less than 0 if date1 represents a point in time before date2,
- greater than 0 if date1 represents a point in time after date2.
- Parameters:
date1-date2-- Returns:
- the relative comparison result.
-
compare
Compares two dates and returns an int value- of 0 if they are equal,
- less than 0 if date1 represents a point in time before date2,
- greater than 0 if date1 represents a point in time after date2.
- Parameters:
date1-date2-- Returns:
- the relative comparison result.
-
between
Compute XML dayTimeDuration between 2 dates. Result will be negative if date1 > date2.- Parameters:
date1- first (earlier) datedate2- second (later) date- Returns:
- XML Duration
-
between
Compute XML dayTimeDuration between 2 dates. Result will be negative if date1 > date2.- Parameters:
date1- first (earlier) datedate2- second (later) date- Returns:
- XML Duration
-
between
Compute XML dayTimeDuration between 2 dates. Result will be negative if date1 > date2.- Parameters:
date1- first (earlier) datedate2- second (later) date- Returns:
- XML Duration
-
between
Compute XML dayTimeDuration between 2 dates. Result will be negative if date1 > date2.- Parameters:
date1- first (earlier) datedate2- second (later) date- Returns:
- XML Duration
-
fromString
create an XML Duration from its lexical representation, e.g. P7DT6H is 7 days 6 hours.- Parameters:
lexicalRepresentation-- Returns:
-
compareDurations
compare 2 XML durations.- Parameters:
duration1-duration2-- Returns:
- -1, 0, or +1 depending on whether duration1 is <, ==, or > duration2, respectively.
- Throws:
IllegalStateException- if the durations are not comparable, e.g. one is a dayTimeDuration and the other is a yearMonthDuration.
-
isDayTimeDuration
is the xml duration a dayTimeDuration?- Parameters:
xmlDuration-- Returns:
- boolean
-
isYearMonthDuration
is the xml duration a yearMonthDuration?- Parameters:
xmlDuration-- Returns:
- boolean
-
getSeconds
Get the seconds from the duration as a BigDecimal.- Parameters:
xmlDuration-- Returns:
- seconds, including fractional part
-
ratio
Divide the first duration by the second duration- Parameters:
xmlDuration1-xmlDuration2-- Returns:
- BigDecimal quotient
-
divide
Divide the given duration by a number- Parameters:
dividend-divisor-- Returns:
- Duration
-
divide
Divide the given duration by a number- Parameters:
dividend-divisor-- Returns:
- Duration
-
multiply
Multiply the given duration by a number- Parameters:
duration-factor-- Returns:
- Duration
-
multiply
Multiply the given duration by a number- Parameters:
duration-factor-- Returns:
- Duration
-