Version 4.10.0

hirondelle.web4j.request
Interface DateConverter


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 :


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

parseHandFriendly

Date parseHandFriendly(String aInputValue,
                       Locale aLocale,
                       TimeZone aTimeZone)
Parse textual user input of a "hand-friendly" format into a 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 Locales.

This method is called by RequestParser.

Parameters:
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.

parseEyeFriendly

Date parseEyeFriendly(String aInputValue,
                      Locale aLocale,
                      TimeZone aTimeZone)
Parse textual user input of an "eye-friendly" format into a 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 Locales.

This method is called by RequestParser.

Parameters:
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.

formatEyeFriendly

String formatEyeFriendly(Date aDate,
                         Locale aLocale,
                         TimeZone aTimeZone)
Format a 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 Locales.

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.

Parameters:
aDate - to be presented to the user in a legible format
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.
Returns:
text compatible with parseEyeFriendly(String, Locale, TimeZone)

parseHandFriendlyDateTime

DateTime parseHandFriendlyDateTime(String aInputValue,
                                   Locale aLocale)
Parse textual user input of a "hand-friendly" format into a 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 Locales.

This method is called by RequestParser.

Parameters:
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.

parseEyeFriendlyDateTime

DateTime parseEyeFriendlyDateTime(String aInputValue,
                                  Locale aLocale)
Parse textual user input of an "eye-friendly" format into a 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 Locales.

This method is called by RequestParser.

Parameters:
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.

formatEyeFriendlyDateTime

String formatEyeFriendlyDateTime(DateTime aDateTime,
                                 Locale aLocale)
Format a 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 Locales.

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.

Parameters:
aDateTime - to be presented to the user in a legible format
aLocale - is obtained from the configured LocaleSource, and passed to this method by the framework.
Returns:
text compatible with parseEyeFriendlyDateTime(String, Locale)

Version 4.10.0

Copyright Hirondelle Systems. Published October 19, 2013 - User Guide - All Docs.