org.apache.wicket.datetime
Class DateConverter

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

public abstract class DateConverter
extends 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
 Date convertToObject(String value, Locale locale)
          Converts the given String value
 String convertToString(Object value, Locale locale)
          Converts the given value to a string.
 boolean getApplyTimeZoneDifference()
          Gets whether to apply the time zone difference when interpreting dates.
protected  TimeZone getClientTimeZone()
          Gets the client's time zone.
 Component getComponent()
           
abstract  String getDatePattern()
           
protected abstract  org.joda.time.format.DateTimeFormatter getFormat()
           
protected  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 Date convertToObject(String value,
                            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 String convertToString(Object value,
                              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 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 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 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–2014 Apache Software Foundation. All rights reserved.