org.apache.wicket.datetime
Class DateConverter

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

public abstract class DateConverter
extends java.lang.Object
implements IConverter

Base class for Joda Time based date converters. It contains the logic to parse and format, optionally taking the time zone difference between clients and the server into account.

Converters of this class are best suited for per-component use.

Author:
eelcohillenius
See Also:
Serialized Form

Constructor Summary
DateConverter(boolean applyTimeZoneDifference)
          Construct.
 
Method Summary
 java.lang.Object convertToObject(java.lang.String value, java.util.Locale locale)
          Converts the given String value
 java.lang.String convertToString(java.lang.Object value, java.util.Locale locale)
          Converts the given value to a string.
 boolean getApplyTimeZoneDifference()
          Gets whether to apply the time zone difference when interpreting dates.
protected  java.util.TimeZone getClientTimeZone()
          Gets the client's time zone.
 Component getComponent()
           
abstract  java.lang.String getDatePattern()
           
protected abstract  org.joda.time.format.DateTimeFormatter getFormat()
           
protected  java.util.Locale getLocale()
          Gets the locale to use.
protected  org.joda.time.DateTimeZone getTimeZone()
          Gets the server time zone.
 void setComponent(Component component)
          Sets component for getting the locale
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateConverter

public DateConverter(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:
applyTimeZoneDifference - whether to apply the difference in time zones between client and server
Method Detail

convertToObject

public java.lang.Object convertToObject(java.lang.String value,
                                        java.util.Locale locale)
Description copied from interface: IConverter
Converts the given String value

Specified by:
convertToObject in interface IConverter
Parameters:
value - The string value to convert
locale - The locale used to convert the value
Returns:
The converted value
See Also:
IConverter.convertToObject(java.lang.String, java.util.Locale)

convertToString

public java.lang.String convertToString(java.lang.Object value,
                                        java.util.Locale locale)
Description copied from interface: IConverter
Converts the given value to a string.

Specified by:
convertToString in interface IConverter
Parameters:
value - The value to convert
locale - The locale used to convert the value
Returns:
The converted string value
See Also:
IConverter.convertToString(java.lang.Object, java.util.Locale)

getApplyTimeZoneDifference

public final boolean getApplyTimeZoneDifference()
Gets whether to apply the time zone difference when interpreting dates.

When 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.

Returns:
whether to apply the difference in time zones between client and server

getComponent

public final Component getComponent()
Returns:
optional component to use for determining the locale.

getDatePattern

public abstract java.lang.String getDatePattern()
Returns:
Gets the pattern that is used for printing and parsing

setComponent

public final void setComponent(Component component)
Sets component for getting the locale

Parameters:
component - optional component to use for determining the locale.

getClientTimeZone

protected java.util.TimeZone getClientTimeZone()
Gets the client's time zone.

Returns:
The client's time zone or null

getFormat

protected abstract org.joda.time.format.DateTimeFormatter getFormat()
Returns:
formatter The formatter for the current conversion

getLocale

protected java.util.Locale getLocale()
Gets the locale to use.

Returns:
the locale from either the component if that is set, or from the session

getTimeZone

protected org.joda.time.DateTimeZone getTimeZone()
Gets the server time zone. Override this method if you want to fix to a certain time zone, regardless of what actual time zone the server is in.

Returns:
The server time zone


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