|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.joda.time.format.DateTimeParserBucket
DateTimeParserBucket is an advanced class, intended mainly for parser implementations. It can also be used during normal parsing operations to capture more information about the parse.
This class allows fields to be saved in any order, but be physically set in a consistent order. This is useful for parsing against formats that allow field values to contradict each other.
Field values are applied in an order where the "larger" fields are set first, making their value less likely to stick. A field is larger than another when it's range duration is longer. If both ranges are the same, then the larger field has the longer duration. If it cannot be determined which field is larger, then the fields are set in the order they were saved.
For example, these fields were saved in this order: dayOfWeek, monthOfYear, dayOfMonth, dayOfYear. When computeMillis is called, the fields are set in this order: monthOfYear, dayOfYear, dayOfMonth, dayOfWeek.
DateTimeParserBucket is mutable and not thread-safe.
Constructor Summary | |
DateTimeParserBucket(long instantLocal,
Chronology chrono,
Locale locale)
Constucts a bucket. |
|
DateTimeParserBucket(long instantLocal,
Chronology chrono,
Locale locale,
Integer pivotYear)
Constucts a bucket, with the option of specifying the pivot year for two-digit year parsing. |
Method Summary | |
long |
computeMillis()
Computes the parsed datetime by setting the saved fields. |
long |
computeMillis(boolean resetFields)
Computes the parsed datetime by setting the saved fields. |
long |
computeMillis(boolean resetFields,
String text)
Computes the parsed datetime by setting the saved fields. |
Chronology |
getChronology()
Gets the chronology of the bucket, which will be a local (UTC) chronology. |
Locale |
getLocale()
Returns the locale to be used during parsing. |
int |
getOffset()
Returns the time zone offset in milliseconds used by computeMillis, unless getZone doesn't return null. |
Integer |
getPivotYear()
Returns the pivot year used for parsing two-digit years. |
DateTimeZone |
getZone()
Returns the time zone used by computeMillis, or null if an offset is used instead. |
boolean |
restoreState(Object savedState)
Restores the state of this bucket from a previously saved state. |
void |
saveField(DateTimeField field,
int value)
Saves a datetime field value. |
void |
saveField(DateTimeFieldType fieldType,
int value)
Saves a datetime field value. |
void |
saveField(DateTimeFieldType fieldType,
String text,
Locale locale)
Saves a datetime field text value. |
Object |
saveState()
Saves the state of this bucket, returning it in an opaque object. |
void |
setOffset(int offset)
Set a time zone offset to be used when computeMillis is called, which overrides the time zone. |
void |
setPivotYear(Integer pivotYear)
Sets the pivot year to use when parsing two digit years. |
void |
setZone(DateTimeZone zone)
Set a time zone to be used when computeMillis is called, which overrides any set time zone offset. |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public DateTimeParserBucket(long instantLocal, Chronology chrono, Locale locale)
instantLocal
- the initial millis from 1970-01-01T00:00:00, local timechrono
- the chronology to uselocale
- the locale to usepublic DateTimeParserBucket(long instantLocal, Chronology chrono, Locale locale, Integer pivotYear)
instantLocal
- the initial millis from 1970-01-01T00:00:00, local timechrono
- the chronology to uselocale
- the locale to usepivotYear
- the pivot year to use when parsing two-digit yearsMethod Detail |
public Chronology getChronology()
public Locale getLocale()
public DateTimeZone getZone()
public void setZone(DateTimeZone zone)
zone
- the date time zone to operate in, or null if UTCpublic int getOffset()
public void setOffset(int offset)
public Integer getPivotYear()
If null is returned, this indicates default behaviour
public void setPivotYear(Integer pivotYear)
If the value is set to null, this will indicate that default behaviour should be used.
pivotYear
- the pivot year to usepublic void saveField(DateTimeField field, int value)
field
- the field, whose chronology must match that of this bucketvalue
- the valuepublic void saveField(DateTimeFieldType fieldType, int value)
fieldType
- the field typevalue
- the valuepublic void saveField(DateTimeFieldType fieldType, String text, Locale locale)
fieldType
- the field typetext
- the text valuelocale
- the locale to usepublic Object saveState()
public boolean restoreState(Object savedState)
savedState
- opaque saved state, returned from saveState
public long computeMillis()
IllegalArgumentException
- if any field is out of rangepublic long computeMillis(boolean resetFields)
resetFields
- false by default, but when true, unsaved field values are cleared
IllegalArgumentException
- if any field is out of rangepublic long computeMillis(boolean resetFields, String text)
resetFields
- false by default, but when true, unsaved field values are clearedtext
- optional text being parsed, to be included in any error message
IllegalArgumentException
- if any field is out of range
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |