Class DateConverter

java.lang.Object
org.wicketstuff.datetime.DateConverter
All Implemented Interfaces:
Serializable, IConverter<Date>, IClusterable
Direct Known Subclasses:
PatternDateConverter, StyleDateConverter

public abstract class DateConverter extends Object implements IConverter<Date>
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:
  • Constructor Details

    • 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 Details

    • convertToObject

      public Date convertToObject(String value, Locale locale)
      Specified by:
      convertToObject in interface IConverter<Date>
      See Also:
    • convertToString

      public String convertToString(Date value, Locale locale)
      Specified by:
      convertToString in interface IConverter<Date>
      See Also:
    • 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
    • getDatePattern

      public abstract String getDatePattern(Locale locale)
      Parameters:
      locale - The locale used to convert the value
      Returns:
      Gets the pattern that is used for printing and parsing
    • 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(Locale locale)
      Parameters:
      locale - The locale used to convert the value
      Returns:
      formatter The formatter for the current conversion
    • 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