public final class CachedDateFormat
extends java.text.DateFormat
Modifier and Type | Field and Description |
---|---|
private java.lang.StringBuffer |
cache
Cache of previous conversion.
|
private static java.lang.String |
DIGITS
Supported digit set.
|
private int |
expiration
Maximum validity period for the cache.
|
private java.text.DateFormat |
formatter
Wrapped formatter.
|
private static int |
MAGIC1
First magic number used to detect the millisecond position.
|
private static int |
MAGIC2
Second magic number used to detect the millisecond position.
|
private static java.lang.String |
MAGICSTRING1
Expected representation of first magic number.
|
private static java.lang.String |
MAGICSTRING2
Expected representation of second magic number.
|
private int |
millisecondStart
Index of initial digit of millisecond pattern or
UNRECOGNIZED_MILLISECONDS or NO_MILLISECONDS.
|
static int |
NO_MILLISECONDS
Constant used to represent that there was no change
observed when changing the millisecond count.
|
private long |
previousTime
Date requested in previous conversion.
|
private static long |
serialVersionUID
Serialization version.
|
private long |
slotBegin
Integral second preceding the previous convered Date.
|
private java.util.Date |
tmpDate
Scratch date object used to minimize date object creation.
|
static int |
UNRECOGNIZED_MILLISECONDS
Constant used to represent that there was an
observed change, but was an expected change.
|
private static java.lang.String |
ZERO_STRING
Expected representation of 0 milliseconds.
|
AM_PM_FIELD, calendar, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, numberFormat, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD
Constructor and Description |
---|
CachedDateFormat(java.text.DateFormat dateFormat,
int expiration)
Creates a new CachedDateFormat object.
|
Modifier and Type | Method and Description |
---|---|
static int |
findMillisecondStart(long time,
java.lang.String formatted,
java.text.DateFormat formatter)
Finds start of millisecond field in formatted time.
|
java.lang.StringBuffer |
format(java.util.Date date,
java.lang.StringBuffer sbuf,
java.text.FieldPosition fieldPosition)
Formats a Date into a date/time string.
|
java.lang.StringBuffer |
format(long now,
java.lang.StringBuffer buf)
Formats a millisecond count into a date/time string.
|
static int |
getMaximumCacheValidity(java.lang.String pattern)
Gets maximum cache validity for the specified SimpleDateTime
conversion pattern.
|
java.text.NumberFormat |
getNumberFormat()
Gets number formatter.
|
private static void |
millisecondFormat(int millis,
java.lang.StringBuffer buf,
int offset)
Formats a count of milliseconds (0-999) into a numeric representation.
|
java.util.Date |
parse(java.lang.String s,
java.text.ParsePosition pos)
This method is delegated to the formatter which most
likely returns null.
|
void |
setTimeZone(java.util.TimeZone timeZone)
Set timezone.
|
clone, equals, format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, hashCode, isLenient, parse, parseObject, setCalendar, setLenient, setNumberFormat
private static final long serialVersionUID
public static final int NO_MILLISECONDS
private static final java.lang.String DIGITS
public static final int UNRECOGNIZED_MILLISECONDS
private static final int MAGIC1
private static final java.lang.String MAGICSTRING1
private static final int MAGIC2
private static final java.lang.String MAGICSTRING2
private static final java.lang.String ZERO_STRING
private final java.text.DateFormat formatter
private int millisecondStart
private long slotBegin
private java.lang.StringBuffer cache
private final int expiration
private long previousTime
private final java.util.Date tmpDate
public CachedDateFormat(java.text.DateFormat dateFormat, int expiration)
dateFormat
- Date format, may not be null.expiration
- maximum cached range in milliseconds.
If the dateFormat is known to be incompatible with the
caching algorithm, use a value of 0 to totally disable
caching or 1 to only use cache for duplicate requests.public static int findMillisecondStart(long time, java.lang.String formatted, java.text.DateFormat formatter)
time
- long time, must be integral number of secondsformatted
- String corresponding formatted stringformatter
- DateFormat date formatpublic java.lang.StringBuffer format(java.util.Date date, java.lang.StringBuffer sbuf, java.text.FieldPosition fieldPosition)
format
in class java.text.DateFormat
date
- the date to format.sbuf
- the string buffer to write to.fieldPosition
- remains untouched.public java.lang.StringBuffer format(long now, java.lang.StringBuffer buf)
now
- Number of milliseconds after midnight 1 Jan 1970 GMT.buf
- the string buffer to write to.private static void millisecondFormat(int millis, java.lang.StringBuffer buf, int offset)
millis
- Millisecond coun between 0 and 999.buf
- String buffer, may not be null.offset
- Starting position in buffer, the length of the
buffer must be at least offset + 3.public void setTimeZone(java.util.TimeZone timeZone)
setTimeZone
in class java.text.DateFormat
timeZone
- TimeZone new timezonepublic java.util.Date parse(java.lang.String s, java.text.ParsePosition pos)
parse
in class java.text.DateFormat
s
- string representation of date.pos
- field position, unused.public java.text.NumberFormat getNumberFormat()
getNumberFormat
in class java.text.DateFormat
public static int getMaximumCacheValidity(java.lang.String pattern)
pattern
- conversion pattern, may not be null.