Package org.apache.wicket.datetime
Class DateConverter
- java.lang.Object
-
- org.apache.wicket.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:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DateConverter(boolean applyTimeZoneDifference)
Construct.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Date
convertToObject(String value, Locale locale)
String
convertToString(Date value, Locale locale)
boolean
getApplyTimeZoneDifference()
Gets whether to apply the time zone difference when interpreting dates.protected TimeZone
getClientTimeZone()
Gets the client's time zone.abstract String
getDatePattern(Locale locale)
protected abstract org.joda.time.format.DateTimeFormatter
getFormat(Locale locale)
protected org.joda.time.DateTimeZone
getTimeZone()
Gets the server time zone.
-
-
-
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)
- Specified by:
convertToObject
in interfaceIConverter<Date>
- See Also:
IConverter.convertToObject(java.lang.String, java.util.Locale)
-
convertToString
public String convertToString(Date value, Locale locale)
- Specified by:
convertToString
in interfaceIConverter<Date>
- 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
-
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
-
-