|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.text.Format
java.text.DateFormat
com.jgoodies.validation.tutorial.formatted.format.RelativeDateFormat
public final class RelativeDateFormat
A Format
that provides special handling for output
shortcuts and relative input.
If output shortcuts are enabled, Yesterday, Today and Tomorrow are formatted using their localized human-language print strings.
If relative input is allowed, the parser accepts signed integers that encode a date relative to today; this input would otherwise be considered invalid.
This class is intended for demonstration purposes only. It is superceded by
the RelativeDateFormatter
.
ValidationUtils
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from class java.text.DateFormat |
---|
DateFormat.Field |
Field Summary | |
---|---|
static String |
KEY_TODAY
The resource key used to lookup the localized text for "Today". |
static String |
KEY_TOMORROW
The resource key used to lookup the localized text for "Tomorrow". |
static String |
KEY_YESTERDAY
The resource key used to lookup the localized text for "Yesterday". |
Fields inherited from class java.text.DateFormat |
---|
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 Summary | |
---|---|
RelativeDateFormat()
Constructs a wrapped format that provides special handling for output shortcuts and relative input. |
|
RelativeDateFormat(DateFormat delegate,
boolean useOutputShortcuts,
boolean allowRelativeInput)
Constructs a wrapped format that provides special handling for output shortcuts and relative input. |
Method Summary | |
---|---|
StringBuffer |
format(Date date,
StringBuffer toAppendTo,
FieldPosition fieldPosition)
Formats a Date into a date/time string. |
static Format |
getDefaultDisplayDateFormat()
Creates and answers the default Format that is used
to edit instances of Date in the UI:
It converts null to empty Strings,
uses the short DateFormat ,
uses shortcuts for output and
does not accepts relative input. |
static Format |
getDefaultEditDateFormat()
Creates and answers the default Format that is used
to edit instances of Date in the UI:
It converts null to empty Strings,
uses the short DateFormat ,
uses shortcuts for output and
accepts relative input. |
static Format |
getDefaultPrintDateFormat()
Creates and answers the default Format that is used
to edit instances of Date in the UI:
It converts null to empty Strings,
uses the short DateFormat ,
does not uses shortcuts for output and
does not accepts relative input. |
ResourceBundle |
getResourceBundle()
|
Date |
parse(String source,
ParsePosition pos)
Parse a date/time string according to the given parse position. |
void |
setResourceBundle(ResourceBundle newBundle)
|
Methods inherited from class java.text.DateFormat |
---|
clone, equals, format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, hashCode, isLenient, parse, parseObject, setCalendar, setLenient, setNumberFormat, setTimeZone |
Methods inherited from class java.text.Format |
---|
format, formatToCharacterIterator, parseObject |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String KEY_YESTERDAY
public static final String KEY_TODAY
public static final String KEY_TOMORROW
Constructor Detail |
---|
public RelativeDateFormat()
public RelativeDateFormat(DateFormat delegate, boolean useOutputShortcuts, boolean allowRelativeInput)
delegate
- the DateFormat to handle format and parse datesuseOutputShortcuts
- true indicates that dates are formatted
with shortcuts for yesterday, today, and tomorrow, where false
always converts using absolute numbers for day, month and year.allowRelativeInput
- true indicates that the parser accepts
signed integers that encode a date relative to today; if false
such input is considered invalidMethod Detail |
---|
public static Format getDefaultEditDateFormat()
Format
that is used
to edit instances of Date
in the UI:
It converts null
to empty Strings,
uses the short DateFormat
,
uses shortcuts for output and
accepts relative input.
public static Format getDefaultDisplayDateFormat()
Format
that is used
to edit instances of Date
in the UI:
It converts null
to empty Strings,
uses the short DateFormat
,
uses shortcuts for output and
does not accepts relative input.
public static Format getDefaultPrintDateFormat()
Format
that is used
to edit instances of Date
in the UI:
It converts null
to empty Strings,
uses the short DateFormat
,
does not uses shortcuts for output and
does not accepts relative input.
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition)
format
in class DateFormat
date
- a Date to be formatted into a date/time string.toAppendTo
- the string buffer for the returning date/time string.fieldPosition
- keeps track of the position of the field
within the returned string.
On input: an alignment field,
if desired. On output: the offsets of the alignment field. For
example, given a time text "1996.07.10 AD at 15:08:56 PDT",
if the given fieldPosition is DateFormat.YEAR_FIELD, the
begin index and end index of fieldPosition will be set to
0 and 4, respectively.
Notice that if the same time field appears
more than once in a pattern, the fieldPosition will be set for the first
occurrence of that time field. For instance, formatting a Date to
the time string "1 PM PDT (Pacific Daylight Time)" using the pattern
"h a z (zzzz)" and the alignment field DateFormat.TIMEZONE_FIELD,
the begin index and end index of fieldPosition will be set to
5 and 8, respectively, for the first occurrence of the timezone
pattern character 'z'.
public Date parse(String source, ParsePosition pos)
By default, parsing is lenient: If the input is not in the form used by this object's format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).
In addition to the delegate's behavior, this methods accepts signed integers interpreted as days relative to today.
parse
in class DateFormat
source
- The date/time string to be parsedpos
- On input, the position at which to start parsing; on
output, the position at which parsing terminated, or the
start position if the parse failed.
DateFormat.setLenient(boolean)
public ResourceBundle getResourceBundle()
public void setResourceBundle(ResourceBundle newBundle)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |