|
Version 4.10.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface DateConverter
Convert text into a DateTime
or Date
object, and vice versa.
See BuildImpl
for important information on how this item is configured.
BuildImpl.forDateConverter()
returns the configured implementation of this interface.
This interface has methods which occur in pairs, one for a DateTime
, and one for a Date
.
The term 'date' used below refers to generically to both of these classes. WEB4J recommeds
DateTime
as the preferred class for representing dates.
The application programmer's implementation of this interface is used when WEB4J needs to build a date from user input, or format an existing date. Here is an example implementation.
Design Notes
Here are some forces concerning dates in Java web applications :
SimpleDateFormat
is mediocre, and perhaps even untrustworthy. It should be used with great care.
One should also be aware that it's not thread-safe.
Locale
is added to an application, then parsing and formatting of a date should not fail.
Instead, reasonable defaults should be defined for unknown Locales.
Method Summary | |
---|---|
String |
formatEyeFriendly(Date aDate,
Locale aLocale,
TimeZone aTimeZone)
Format a Date into an eye-friendly, legible format. |
String |
formatEyeFriendlyDateTime(DateTime aDateTime,
Locale aLocale)
Format a DateTime into an eye-friendly, legible format. |
Date |
parseEyeFriendly(String aInputValue,
Locale aLocale,
TimeZone aTimeZone)
Parse textual user input of an "eye-friendly" format into a Date object. |
DateTime |
parseEyeFriendlyDateTime(String aInputValue,
Locale aLocale)
Parse textual user input of an "eye-friendly" format into a DateTime object. |
Date |
parseHandFriendly(String aInputValue,
Locale aLocale,
TimeZone aTimeZone)
Parse textual user input of a "hand-friendly" format into a Date object. |
DateTime |
parseHandFriendlyDateTime(String aInputValue,
Locale aLocale)
Parse textual user input of a "hand-friendly" format into a DateTime object. |
Method Detail |
---|
Date parseHandFriendly(String aInputValue, Locale aLocale, TimeZone aTimeZone)
Date
object.
A hand-friendly format might be '01312006', while an eye-friendly format might be 'Jan 31, 2006'.
The implementation must return null when the user input cannot be
successfully parsed into a Date
. It is recommended that the implementation
have reasonable default behaviour for unexpected Locale
s.
This method is called by RequestParser
.
aInputValue
- user input value, as returned by ConvertParam.filter(String)
(always has content).aLocale
- is obtained from the configured LocaleSource
, and passed to this method
by the framework.aTimeZone
- is obtained from the configured TimeZoneSource
, and passed to this method
by the framework.Date parseEyeFriendly(String aInputValue, Locale aLocale, TimeZone aTimeZone)
Date
object.
A hand-friendly format might be '01312006', while an eye-friendly format might be 'Jan 31, 2006'.
The implementation must return null when the user input cannot be
successfully parsed into a Date
. It is recommended that the implementation
have reasonable default behaviour for unexpected Locale
s.
This method is called by RequestParser
.
aInputValue
- user input value, as returned by ConvertParam.filter(String)
(always has content).aLocale
- is obtained from the configured LocaleSource
, and passed to this method
by the framework.aTimeZone
- is obtained from the configured TimeZoneSource
, and passed to this method
by the framework.String formatEyeFriendly(Date aDate, Locale aLocale, TimeZone aTimeZone)
Date
into an eye-friendly, legible format.
The implementation must return an empty String when the Date
is null.
It is recommended that the implementation have reasonable default behaviour for unexpected Locale
s.
The framework will call this method when presenting listings using
Report
, and when presenting a Model Object in a form
for a "change" operation.
This method is called by Formats
.
aDate
- to be presented to the user in a legible formataLocale
- is obtained from the configured LocaleSource
, and passed to this method
by the framework.aTimeZone
- is obtained from the configured TimeZoneSource
, and passed to this method
by the framework.
parseEyeFriendly(String, Locale, TimeZone)
DateTime parseHandFriendlyDateTime(String aInputValue, Locale aLocale)
DateTime
object.
A hand-friendly format might be '01312006', while an eye-friendly format might be 'Jan 31, 2006'.
The implementation must return null when the user input cannot be
successfully parsed into a DateTime
. It is recommended that the implementation
have reasonable default behaviour for unexpected Locale
s.
This method is called by RequestParser
.
aInputValue
- user input value, as returned by ConvertParam.filter(String)
(always has content).aLocale
- is obtained from the configured LocaleSource
, and passed to this method
by the framework.DateTime parseEyeFriendlyDateTime(String aInputValue, Locale aLocale)
DateTime
object.
A hand-friendly format might be '01312006', while an eye-friendly format might be 'Jan 31, 2006'.
The implementation must return null when the user input cannot be
successfully parsed into a DateTime
. It is recommended that the implementation
have reasonable default behaviour for unexpected Locale
s.
This method is called by RequestParser
.
aInputValue
- user input value, as returned by ConvertParam.filter(String)
(always has content).aLocale
- is obtained from the configured LocaleSource
, and passed to this method
by the framework.String formatEyeFriendlyDateTime(DateTime aDateTime, Locale aLocale)
DateTime
into an eye-friendly, legible format.
The implementation must return an empty String when the DateTime
is null.
It is recommended that the implementation have reasonable default behaviour for unexpected Locale
s.
The framework will call this method when presenting listings using
Report
, and when presenting a Model Object in a form
for a "change" operation.
This method is called by Formats
.
aDateTime
- to be presented to the user in a legible formataLocale
- is obtained from the configured LocaleSource
, and passed to this method
by the framework.
parseEyeFriendlyDateTime(String, Locale)
|
Version 4.10.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |