Package csv.impl.type

Class DateConversionHandler

java.lang.Object
csv.impl.type.DateConversionHandler
All Implemented Interfaces:
TypeConversionHandler

public class DateConversionHandler
extends java.lang.Object
implements TypeConversionHandler
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 
    Modifier and Type Field Description
    static DateConversionHandler INSTANCE  
  • Constructor Summary

    Constructors 
    Constructor Description
    DateConversionHandler()
    Constructor.
  • Method Summary

    Modifier and Type Method Description
    java.lang.String[] getParsingFormats()
    Returns the formats that will be used.
    java.text.DateFormat[] getParsingFormatters()
    Returns the date formatters created from our date formatters.
    protected java.text.DateFormat[] getParsingFormatters​(java.lang.String s)
    Returns date formatters that fit the given string.
    java.lang.String getPrintFormat()
    Returns the printing format.
    java.text.DateFormat getPrintFormatter()
    Returns the print formatter created from the print format.
    java.util.TimeZone getTimezone()
    Returns the timezone this handler uses.
    java.lang.String[] getTypes()
    Returns th type java.util.Date.
    protected boolean matches​(java.lang.String format, java.lang.String s)  
    void setParsingFormats​(java.lang.String[] parsingFormats)
    Sets the parsing date formats to be used.
    void setPrintFormat​(java.lang.String printFormat)
    Sets the format used for printing.
    void setTimezone​(java.util.TimeZone timezone)
    Sets the timezone for formatting and parsing.
    java.lang.Object toObject​(java.lang.String s)
    Converts string to date.
    java.lang.String toString​(java.lang.Object o)
    Converts the date to its string representation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • getTypes

      public java.lang.String[] getTypes()
      Returns th type java.util.Date.
      Specified by:
      getTypes in interface TypeConversionHandler
      Returns:
      type strings
      See Also:
      TypeConversionHandler.getTypes()
    • toObject

      public java.lang.Object toObject​(java.lang.String s)
      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:
      toObject in interface TypeConversionHandler
      Parameters:
      s - string to be parsed
      Returns:
      date
      See Also:
      TypeConversionHandler.toObject(java.lang.String)
    • toString

      public java.lang.String toString​(java.lang.Object o)
      Converts the date to its string representation.
      Specified by:
      toString in interface TypeConversionHandler
      Parameters:
      o - date to be converted
      Returns:
      string representation of date
      See Also:
      TypeConversionHandler.toString(java.lang.Object)
    • getParsingFormatters

      public java.text.DateFormat[] getParsingFormatters()
      Returns the date formatters created from our date formatters.
      Returns:
      array of formatters to be used (never null!)
    • getParsingFormatters

      protected java.text.DateFormat[] getParsingFormatters​(java.lang.String s)
      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

      protected boolean matches​(java.lang.String format, java.lang.String s)
    • getParsingFormats

      public java.lang.String[] 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

      public void setParsingFormats​(java.lang.String[] parsingFormats)
      Sets the parsing date formats to be used.
      Parameters:
      parsingFormats - the parsingFormats to set
    • getPrintFormat

      public java.lang.String getPrintFormat()
      Returns the printing format. This method will return the first parsing format if no format was set.
      Returns:
      the printFormat
    • setPrintFormat

      public void setPrintFormat​(java.lang.String printFormat)
      Sets the format used for printing.
      Parameters:
      printFormat - the printFormat to set
    • getPrintFormatter

      public java.text.DateFormat getPrintFormatter()
      Returns the print formatter created from the print format.
      Returns:
      print formatter
    • setTimezone

      public void setTimezone​(java.util.TimeZone timezone)
      Sets the timezone for formatting and parsing.
      Parameters:
      timezone - timezone to be used.
    • getTimezone

      public java.util.TimeZone getTimezone()
      Returns the timezone this handler uses.
      Returns:
      timezone