|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.alfresco.service.cmr.repository.datatype.Duration
public class Duration
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.
Field Summary | |
---|---|
static Duration |
DAY
|
static Duration |
MONTH
|
static Duration |
QUARTER
|
static Duration |
SIX_MONTHS
|
static Duration |
TWO_WEEKS
|
static Duration |
WEEK
|
static java.lang.String |
XML_DAY
|
static java.lang.String |
XML_MONTH
|
static java.lang.String |
XML_QUARTER
|
static java.lang.String |
XML_SIX_MONTHS
|
static java.lang.String |
XML_TWO_WEEKS
|
static java.lang.String |
XML_WEEK
|
static java.lang.String |
XML_YEAR
|
static Duration |
YEAR
|
Constructor Summary | |
---|---|
Duration()
Constructor for Duration - a zero value duration |
|
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. |
|
Duration(java.util.Date date)
Create a duration given a date. |
|
Duration(java.util.Date start_in,
java.util.Date end_in)
Construct a preiod between the two given dates |
|
Duration(java.lang.String duration)
Construct a Duration from the XMLSchema definition |
|
Duration(java.lang.String start,
java.lang.String end)
Create a duration betweeen two dates expressed as strings. |
Method Summary | |
---|---|
static java.util.Date |
add(java.util.Date date,
Duration duration)
Add a duration to a date and return the date plus the specified increment. |
Duration |
add(Duration add)
Add two durations together |
int |
compareTo(java.lang.Object o)
Compare two durations |
Duration |
divide(int d)
Divide the duration - if year-month drops the day-second part of the duration |
boolean |
equals(java.lang.Object o)
|
java.lang.String |
formattedString()
Format in human readable form TODO: I18n |
Duration |
getDayToYear()
Extract the day to sec part. |
Duration |
getYearToMonth()
Extract the year to month part |
int |
hashCode()
|
boolean |
hasTime()
Check if it includes time |
boolean |
isDayToSec()
Check if is day-sec |
boolean |
isYearToMonth()
Check if is year-month |
static void |
main(java.lang.String[] args)
TODO: Tests that should be moved into a unit test |
static java.util.Date |
subtract(java.util.Date date,
Duration duration)
Subtract a period for a given date |
Duration |
subtract(Duration sub)
Subtract one duration from another |
java.lang.String |
toString()
Produce the XML Schema string |
Duration |
unaryMinus()
Negate the duration |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String XML_DAY
public static final java.lang.String XML_WEEK
public static final java.lang.String XML_TWO_WEEKS
public static final java.lang.String XML_MONTH
public static final java.lang.String XML_QUARTER
public static final java.lang.String XML_SIX_MONTHS
public static final java.lang.String XML_YEAR
public static final Duration DAY
public static final Duration WEEK
public static final Duration TWO_WEEKS
public static final Duration MONTH
public static final Duration QUARTER
public static final Duration SIX_MONTHS
public static final Duration YEAR
Constructor Detail |
---|
public Duration()
public Duration(java.lang.String duration)
public Duration(java.util.Date date)
public Duration(java.lang.String start, java.lang.String end)
start
- - the date at the start of the periodend
- - the date at the end of the periodpublic Duration(java.util.Date start_in, java.util.Date end_in)
start_in
- end_in
- public Duration(boolean positive_in, long months_in, long seconds_in, long nanos_in)
Method Detail |
---|
public static java.util.Date add(java.util.Date date, Duration duration)
date
- - the initial dateduration
- - the duration to add on to the date (the duration may be negative)
public static java.util.Date subtract(java.util.Date date, Duration duration)
date
- - the intial dateduration
- - the diration to subtract
public Duration add(Duration add)
public Duration subtract(Duration sub)
public Duration unaryMinus()
public Duration divide(int d)
public boolean isYearToMonth()
public boolean isDayToSec()
public boolean hasTime()
public Duration getYearToMonth()
public Duration getDayToYear()
public int compareTo(java.lang.Object o)
compareTo
in interface java.lang.Comparable
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
Object.equals(Object)
public int hashCode()
hashCode
in class java.lang.Object
Object.hashCode()
public java.lang.String toString()
toString
in class java.lang.Object
Object.toString()
public java.lang.String formattedString()
public static void main(java.lang.String[] args)
args
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |