public class DateTimeParserBucket
extends java.lang.Object
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 and Description |
---|
DateTimeParserBucket(long instantLocal,
Chronology chrono,
java.util.Locale locale)
Deprecated.
Use longer constructor
|
DateTimeParserBucket(long instantLocal,
Chronology chrono,
java.util.Locale locale,
java.lang.Integer pivotYear)
Deprecated.
Use longer constructor
|
DateTimeParserBucket(long instantLocal,
Chronology chrono,
java.util.Locale locale,
java.lang.Integer pivotYear,
int defaultYear)
Constructs a bucket, with the option of specifying the pivot year for
two-digit year parsing.
|
Modifier and Type | Method and Description |
---|---|
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,
java.lang.CharSequence text)
Computes the parsed datetime by setting the saved fields.
|
long |
computeMillis(boolean resetFields,
java.lang.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.
|
java.util.Locale |
getLocale()
Returns the locale to be used during parsing.
|
int |
getOffset()
Deprecated.
use Integer version
|
java.lang.Integer |
getOffsetInteger()
Returns the time zone offset in milliseconds used by computeMillis.
|
java.lang.Integer |
getPivotYear()
Returns the default year used when information is incomplete.
|
DateTimeZone |
getZone()
Returns the time zone used by computeMillis.
|
long |
parseMillis(DateTimeParser parser,
java.lang.CharSequence text)
Parses a datetime from the given text, returning the number of
milliseconds since the epoch, 1970-01-01T00:00:00Z.
|
void |
reset()
Resets the state back to that when the object was constructed.
|
boolean |
restoreState(java.lang.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,
java.lang.String text,
java.util.Locale locale)
Saves a datetime field text value.
|
java.lang.Object |
saveState()
Saves the state of this bucket, returning it in an opaque object.
|
void |
setOffset(int offset)
Deprecated.
use Integer version
|
void |
setOffset(java.lang.Integer offset)
Set a time zone offset to be used when computeMillis is called.
|
void |
setPivotYear(java.lang.Integer pivotYear)
Deprecated.
this method should never have been public
|
void |
setZone(DateTimeZone zone)
Set a time zone to be used when computeMillis is called.
|
@Deprecated public DateTimeParserBucket(long instantLocal, Chronology chrono, java.util.Locale locale)
instantLocal
- the initial millis from 1970-01-01T00:00:00, local timechrono
- the chronology to uselocale
- the locale to use@Deprecated public DateTimeParserBucket(long instantLocal, Chronology chrono, java.util.Locale locale, java.lang.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 yearspublic DateTimeParserBucket(long instantLocal, Chronology chrono, java.util.Locale locale, java.lang.Integer pivotYear, int defaultYear)
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 yearsdefaultYear
- the default year to use when parsing month-daypublic void reset()
This resets the state of the bucket, allowing a single bucket to be re-used for many parses. The bucket must not be shared between threads.
public long parseMillis(DateTimeParser parser, java.lang.CharSequence text)
This parses the text using the parser into this bucket. The bucket is reset before parsing begins, allowing the bucket to be re-used. The bucket must not be shared between threads.
parser
- the parser to use, see DateTimeFormatter.getParser()
, not nulltext
- text to parse, not nulljava.lang.UnsupportedOperationException
- if parsing is not supportedjava.lang.IllegalArgumentException
- if the text to parse is invalidpublic Chronology getChronology()
public java.util.Locale getLocale()
public DateTimeZone getZone()
public void setZone(DateTimeZone zone)
@Deprecated public int getOffset()
public java.lang.Integer getOffsetInteger()
@Deprecated public void setOffset(int offset)
public void setOffset(java.lang.Integer offset)
public java.lang.Integer getPivotYear()
This is used for two-digit years and when the largest parsed field is months or days.
A null value for two-digit years means to use the value from DateTimeFormatterBuilder. A null value for month/day only parsing will cause the default of 2000 to be used.
@Deprecated public void setPivotYear(java.lang.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, java.lang.String text, java.util.Locale locale)
fieldType
- the field typetext
- the text valuelocale
- the locale to usepublic java.lang.Object saveState()
public boolean restoreState(java.lang.Object savedState)
savedState
- opaque saved state, returned from saveStatepublic long computeMillis()
java.lang.IllegalArgumentException
- if any field is out of rangepublic long computeMillis(boolean resetFields)
resetFields
- false by default, but when true, unsaved field values are clearedjava.lang.IllegalArgumentException
- if any field is out of rangepublic long computeMillis(boolean resetFields, java.lang.String text)
resetFields
- false by default, but when true, unsaved field values are clearedtext
- optional text being parsed, to be included in any error messagejava.lang.IllegalArgumentException
- if any field is out of rangepublic long computeMillis(boolean resetFields, java.lang.CharSequence text)
resetFields
- false by default, but when true, unsaved field values are clearedtext
- optional text being parsed, to be included in any error messagejava.lang.IllegalArgumentException
- if any field is out of range"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"