Class Duration
java.lang.Object
org.alfresco.service.cmr.repository.datatype.Duration
- All Implemented Interfaces:
Serializable
,Comparable
This data type represents duration/interval/period as defined by the XMLSchema type
duration.
The lexical representation of duration is
PnYnMnDTnHnMnS.
P is a literal value that starts the expression
nY is an integer number of years followed by the literal Y
nM is an integer number of months followed by the literal M
nD is an integer number of days followed by the literal D
T is the literal that separates the date and time
nH is an integer number of hours followed by a literal H
nM is an integer number of minutes followed by a literal M
nS is a decimal number of seconds followed by a literal S
Any numbers and designator may be absent if the value is zero.
A minus sign may appear before the literal P to indicate a negative duration.
If no time items are present the literal T must not appear.
This implementation is immutable and thread safe.
There are two forms of duration common on database types.
The code contains warnings wheer these are relevant.
- Author:
- andyh
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Duration
static final Duration
static final Duration
static final Duration
static final Duration
static final Duration
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final Duration
-
Constructor Summary
ConstructorsConstructorDescriptionDuration()
Constructor for Duration - a zero value durationDuration
(boolean positive_in, long months_in, long seconds_in, long nanos_in) Construct a duration from months seconds and nanos Checks sign and fixes up seconds and nano.Construct a Duration from the XMLSchema definitionCreate a duration betweeen two dates expressed as strings.Create a duration given a date.Construct a preiod between the two given dates -
Method Summary
Modifier and TypeMethodDescriptionstatic Date
Add a duration to a date and return the date plus the specified increment.Add two durations togetherint
Compare two durationsdivide
(int d) Divide the duration - if year-month drops the day-second part of the durationboolean
Format in human readable form TODO: I18nExtract the day to sec part.Extract the year to month partint
hashCode()
boolean
hasTime()
Check if it includes timeboolean
Check if is day-secboolean
Check if is year-monthstatic void
TODO: Tests that should be moved into a unit teststatic Date
Subtract a period for a given dateSubtract one duration from anothertoString()
Produce the XML Schema stringNegate the duration
-
Field Details
-
XML_DAY
- See Also:
-
XML_WEEK
- See Also:
-
XML_TWO_WEEKS
- See Also:
-
XML_MONTH
- See Also:
-
XML_QUARTER
- See Also:
-
XML_SIX_MONTHS
- See Also:
-
XML_YEAR
- See Also:
-
DAY
-
WEEK
-
TWO_WEEKS
-
MONTH
-
QUARTER
-
SIX_MONTHS
-
YEAR
-
-
Constructor Details
-
Duration
public Duration()Constructor for Duration - a zero value duration -
Duration
Construct a Duration from the XMLSchema definition -
Duration
Create a duration given a date. The duration is between the two dates provided. Sadly, it works out the duration by incrementing the lower calendar until it matches the higher. -
Duration
Create a duration betweeen two dates expressed as strings. Uses the standard XML date form.- Parameters:
start
- - the date at the start of the periodend
- - the date at the end of the period
-
Duration
Construct a preiod between the two given dates- Parameters:
start_in
- Dateend_in
- Date
-
Duration
public Duration(boolean positive_in, long months_in, long seconds_in, long nanos_in) Construct a duration from months seconds and nanos Checks sign and fixes up seconds and nano. Treats year-month abd day-sec as separate chunks
-
-
Method Details
-
add
Add a duration to a date and return the date plus the specified increment.- Parameters:
date
- - the initial dateduration
- - the duration to add on to the date (the duration may be negative)- Returns:
- the adjusted date.
-
subtract
Subtract a period for a given date- Parameters:
date
- - the intial dateduration
- - the diration to subtract- Returns:
- the adjusted date.
-
add
Add two durations together -
subtract
Subtract one duration from another -
unaryMinus
Negate the duration -
divide
Divide the duration - if year-month drops the day-second part of the duration -
isYearToMonth
public boolean isYearToMonth()Check if is year-month -
isDayToSec
public boolean isDayToSec()Check if is day-sec -
hasTime
public boolean hasTime()Check if it includes time -
getYearToMonth
Extract the year to month part -
getDayToYear
Extract the day to sec part. -
compareTo
Compare two durations- Specified by:
compareTo
in interfaceComparable
-
equals
-
hashCode
public int hashCode() -
toString
Produce the XML Schema string -
largestComponentformattedString
-
formattedString
Format in human readable form TODO: I18n -
main
TODO: Tests that should be moved into a unit test- Parameters:
args
- String[]
-