public class DateFormatter extends DateFormatParser
Modifier and Type | Field and Description |
---|---|
private boolean |
deferredValueError
Set to true when the first "value cannot be formatted" error is occurred.
|
private java.lang.String |
format
The date format, used for error reporting.
|
private byte[] |
order
The date component order spec: array of 3 elements.
|
private java.lang.StringBuilder |
sb
The output formatted value collector
|
private date |
value
The date to format
|
Constructor and Description |
---|
DateFormatter(date value,
java.lang.String format,
byte[] order)
The constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
format()
Format date using the specified format string.
|
private void |
formatDayOrMonth(int startIdx,
int endIdx,
int number)
Format day or month component.
|
private static java.lang.String |
formatField(int number,
int minimumLen)
Format one date component.
|
private java.lang.String |
toYearString(int max)
Generate a string representation of the year based on the unusual
rules of the Progress 4GL.
|
protected void |
visitDateComponent(int componentIndex,
int startIdx,
int endIdx)
Dispatch the date component to a matching callback.
|
protected void |
visitDay(int startIdx,
int endIdx)
The day component of the date spec.
|
protected void |
visitMonth(int startIdx,
int endIdx)
The the month component of the date spec.
|
protected void |
visitSep1(char sep)
The first date component separator was parsed: one of '.', '-' or '/'.
|
protected void |
visitSep2(char sep)
The second date component separator was parsed: one of '.', '-' or '/'.
|
protected void |
visitYear(int startIdx,
int endIdx)
The the year component of the date spec.
|
parse
private final date value
private final java.lang.StringBuilder sb
private final java.lang.String format
private boolean deferredValueError
private final byte[] order
date.YEAR
,
date.MONTH
, or date.DAY
public DateFormatter(date value, java.lang.String format, byte[] order)
value
- the date instance to formatformat
- the date format to useorder
- The date component order spec: array of 3 elements. Values can be date.YEAR
,
date.MONTH
, or date.DAY
.public java.lang.String format()
protected void visitYear(int startIdx, int endIdx)
Note: the length of the first date component can be zero.
startIdx
- the component start index, zero basedendIdx
- the component end index, zero based, exclusiveprotected void visitMonth(int startIdx, int endIdx)
Note: the length of the component can be zero.
startIdx
- the component start index, zero basedendIdx
- the component end index, zero based, exclusiveprotected void visitDay(int startIdx, int endIdx)
Note: the length of the component can be zero.
startIdx
- the component start index, zero basedendIdx
- the component end index, zero based, exclusiveprotected final void visitDateComponent(int componentIndex, int startIdx, int endIdx)
visitDateComponent
in class DateFormatParser
componentIndex
- the number of the component in the format specstartIdx
- the component start index, zero basedendIdx
- the component end index, zero based, exclusiveprotected void visitSep1(char sep)
Subclasses are expected to overload this method, default implementation does nothing.
Note: if date format has no separators, this callback is never called.
visitSep1
in class DateFormatParser
sep
- the first separator characterprotected void visitSep2(char sep)
Subclasses are expected to overload this method, default implementation does nothing.
Note: if date format has no separators, this callback is never called.
visitSep2
in class DateFormatParser
sep
- the second separator characterprivate void formatDayOrMonth(int startIdx, int endIdx, int number)
startIdx
- the component start index in the format stringendIdx
- the component end index in the format stringnumber
- the value to formatprivate java.lang.String toYearString(int max)
max
- Specifies the maximum number of output characters. If the
result cannot fit into this number of characters, then
a null
string will be returned. As a special
case, years within the Y2K window will be truncated to
1 (if possible without losing data) or 2 characters if
max is set to these values respectively. All other values
must 'naturally' fit inside the maximum.null
if the result is
too large to fit.private static final java.lang.String formatField(int number, int minimumLen)
number
- the number to formatminimumLen
- the minimum number of digits