Package csv.impl.csv.type
Class DateConversionHandler
java.lang.Object
csv.impl.csv.type.DateConversionHandler
- All Implemented Interfaces:
TypeConverter
A conversion handler for dates. The default implementation
can recognize these date strings: dd/MM/yyyy, dd.MM.yyyy,
dd/MM/yy, dd.MM.yy, yyyy/MM/dd, yyyy.MM.dd. Please not that
for a specific date string the first suitable format will be used.
- Author:
- ralph
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfromStream(Object o) Converts string to date.String[]Returns the formats that will be used.Returns the date formatters created from our date formatters.protected DateFormat[]Returns date formatters that fit the given string.Returns the printing format.Returns the print formatter created from the print format.Returns the timezone this handler uses.Class<?>[]getTypes()Returns the types that this handler is responsible for.protected booleanvoidsetParsingFormats(String[] parsingFormats) Sets the parsing date formats to be used.voidsetPrintFormat(String printFormat) Sets the format used for printing.voidsetTimezone(TimeZone timezone) Sets the timezone for formatting and parsing.Converts the date to its string representation.
-
Field Details
-
INSTANCE
-
-
Constructor Details
-
DateConversionHandler
public DateConversionHandler()Constructor.
-
-
Method Details
-
getTypes
Returns the types that this handler is responsible for.- Specified by:
getTypesin interfaceTypeConverter- Returns:
- type strings
-
fromStream
Converts string to date. This method tries to parse the given string by checking each possible date format. If no format applies then the original string will be returned- Specified by:
fromStreamin interfaceTypeConverter- Parameters:
o- object from stream.s- string to be parsed- Returns:
- date
- See Also:
-
toStream
Converts the date to its string representation.- Specified by:
toStreamin interfaceTypeConverter- Parameters:
o- date to be converted- Returns:
- string representation of date
- See Also:
-
getParsingFormatters
Returns the date formatters created from our date formatters.- Returns:
- array of formatters to be used (never null!)
-
getParsingFormatters
Returns date formatters that fit the given string. This pre-selection is required due to some unexpected results when it comes to parsing (e.g. 2 digits are excepted by parsers when 4 were required).- Parameters:
s- the string to analyze- Returns:
- array of formatters to be used (never null!)
-
matches
-
getParsingFormats
Returns the formats that will be used. This method returns default formats when no formats were set- Returns:
- the format strings used for parsing dates (never null!).
-
setParsingFormats
Sets the parsing date formats to be used.- Parameters:
parsingFormats- the parsingFormats to set
-
getPrintFormat
Returns the printing format. This method will return the first parsing format if no format was set.- Returns:
- the printFormat
-
setPrintFormat
Sets the format used for printing.- Parameters:
printFormat- the printFormat to set
-
getPrintFormatter
Returns the print formatter created from the print format.- Returns:
- print formatter
-
setTimezone
Sets the timezone for formatting and parsing.- Parameters:
timezone- timezone to be used.
-
getTimezone
Returns the timezone this handler uses.- Returns:
- timezone
-