org.apache.wicket.datetime
Class PatternDateConverter

java.lang.Object
  extended by org.apache.wicket.datetime.DateConverter
      extended by org.apache.wicket.datetime.PatternDateConverter
All Implemented Interfaces:
java.io.Serializable, IClusterable, IConverter

public class PatternDateConverter
extends DateConverter

Date converter that uses Joda Time and can be configured to take the time zone difference between clients and server into account. This converter is hard coded to use the provided custom date pattern, no matter what current locale is used. See SimpleDateFormat for available patterns.

This converter is especially suited on a per-component base.

Author:
eelcohillenius
See Also:
SimpleDateFormat, StyleDateConverter, DateTextField, DateTime, DateTimeFormat, DateTimeZone, Serialized Form

Constructor Summary
PatternDateConverter(java.lang.String datePattern, boolean applyTimeZoneDifference)
          Construct.
 
Method Summary
 java.lang.String getDatePattern()
          Gets the optional date pattern.
protected  org.joda.time.format.DateTimeFormatter getFormat()
           
 
Methods inherited from class org.apache.wicket.datetime.DateConverter
convertToObject, convertToString, getApplyTimeZoneDifference, getClientTimeZone, getComponent, getLocale, getTimeZone, setComponent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PatternDateConverter

public PatternDateConverter(java.lang.String datePattern,
                            boolean applyTimeZoneDifference)
Construct.

When applyTimeZoneDifference is true, the current time is applied on the parsed date, and the date will be corrected for the time zone difference between the server and the client. For instance, if I'm in Seattle and the server I'm working on is in Amsterdam, the server is 9 hours ahead. So, if I'm inputting say 12/24 at a couple of hours before midnight, at the server it is already 12/25. If this boolean is true, it will be transformed to 12/25, while the client sees 12/24.

Parameters:
datePattern - The pattern to use. Must be not null. See SimpleDateFormat for available patterns.
applyTimeZoneDifference - whether to apply the difference in time zones between client and server
Throws:
java.lang.IllegalArgumentException - in case the date pattern is null
Method Detail

getDatePattern

public final java.lang.String getDatePattern()
Gets the optional date pattern.

Specified by:
getDatePattern in class DateConverter
Returns:
datePattern

getFormat

protected org.joda.time.format.DateTimeFormatter getFormat()
Specified by:
getFormat in class DateConverter
Returns:
formatter The formatter for the current conversion


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.