Package org.beanio.types
Class DateTypeHandlerSupport
- java.lang.Object
-
- org.beanio.types.LocaleSupport
-
- org.beanio.types.DateTypeHandlerSupport
-
- All Implemented Interfaces:
java.lang.Cloneable,ConfigurableTypeHandler,TypeHandler
- Direct Known Subclasses:
CalendarTypeHandler,DateTypeHandler
public abstract class DateTypeHandlerSupport extends LocaleSupport implements ConfigurableTypeHandler, java.lang.Cloneable
This abstract type handler uses aSimpleDateFormatclass to parse and formatjava.util.Dateobjects. If no pattern is set,DateFormat.getInstance()is used to create a default date format. By default,lenientis false.- Since:
- 2.1.0
- See Also:
Date,DateFormat,SimpleDateFormat
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanlenientprotected java.lang.Stringpatternprotected java.util.TimeZonetimeZone-
Fields inherited from class org.beanio.types.LocaleSupport
locale
-
Fields inherited from interface org.beanio.types.ConfigurableTypeHandler
FORMAT_SETTING
-
Fields inherited from interface org.beanio.types.TypeHandler
NIL
-
-
Constructor Summary
Constructors Constructor Description DateTypeHandlerSupport()Constructs a new AbstractDateTypeHandler.DateTypeHandlerSupport(java.lang.String pattern)Constructs a new AbstractDateTypeHandler.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.text.DateFormatcreateDateFormat()Creates theDateFormatto use to parse and format the field value.protected java.text.DateFormatcreateDefaultDateFormat()Creates a default date format when no pattern is set.protected java.lang.StringformatDate(java.util.Date date)Converts aDateto text.java.lang.StringgetPattern()Returns the date pattern used by theSimpleDateFormat.java.util.TimeZonegetTimeZone()Returns the configuredTimeZoneor null if not set.java.lang.StringgetTimeZoneId()Returns the time zone used to interpret dates, ornullif the default time zone will be used.booleanisLenient()Returns whether theSimpleDateFormatis lenient.DateTypeHandlerSupportnewInstance(java.util.Properties properties)Creates a customized instance of this type handler.protected java.util.DateparseDate(java.lang.String text)Parses text into aDate.voidsetLenient(boolean lenient)Sets whether theSimpleDateFormatis lenient.voidsetPattern(java.lang.String pattern)Sets the date pattern used by theSimpleDateFormat.voidsetTimeZoneId(java.lang.String name)Sets the time zone for interpreting dates.-
Methods inherited from class org.beanio.types.LocaleSupport
getLocale, setLocale
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.beanio.types.TypeHandler
format, getType, parse
-
-
-
-
Method Detail
-
parseDate
protected java.util.Date parseDate(java.lang.String text) throws TypeConversionExceptionParses text into aDate.- Parameters:
text- the text to parse- Returns:
- the parsed
Date - Throws:
TypeConversionException
-
formatDate
protected java.lang.String formatDate(java.util.Date date)
Converts aDateto text.- Parameters:
date- theDateto convert- Returns:
- the formatted text
-
createDateFormat
protected java.text.DateFormat createDateFormat()
Creates theDateFormatto use to parse and format the field value.- Returns:
- the
DateFormatfor type conversion
-
createDefaultDateFormat
protected java.text.DateFormat createDefaultDateFormat()
Creates a default date format when no pattern is set.- Returns:
- the default date format
-
newInstance
public DateTypeHandlerSupport newInstance(java.util.Properties properties) throws java.lang.IllegalArgumentException
Description copied from interface:ConfigurableTypeHandlerCreates a customized instance of this type handler.- Specified by:
newInstancein interfaceConfigurableTypeHandler- Parameters:
properties- the properties for customizing the instance- Returns:
- the new
TypeHandler - Throws:
java.lang.IllegalArgumentException- if a property value is invalid
-
getPattern
public java.lang.String getPattern()
Returns the date pattern used by theSimpleDateFormat.- Returns:
- the date pattern
-
setPattern
public void setPattern(java.lang.String pattern) throws java.lang.IllegalArgumentExceptionSets the date pattern used by theSimpleDateFormat.- Parameters:
pattern- the date pattern- Throws:
java.lang.IllegalArgumentException- if the date pattern is invalid
-
setTimeZoneId
public void setTimeZoneId(java.lang.String name)
Sets the time zone for interpreting dates. If not set, the system default time zone is used.- Parameters:
name- the time zone ID- See Also:
TimeZone
-
getTimeZoneId
public java.lang.String getTimeZoneId()
Returns the time zone used to interpret dates, ornullif the default time zone will be used.- Returns:
- the time zone ID
- See Also:
TimeZone
-
getTimeZone
public java.util.TimeZone getTimeZone()
Returns the configuredTimeZoneor null if not set.- Returns:
- the
TimeZone
-
isLenient
public boolean isLenient()
Returns whether theSimpleDateFormatis lenient.- Returns:
trueif lenient,falseotherwise
-
setLenient
public void setLenient(boolean lenient)
Sets whether theSimpleDateFormatis lenient.- Parameters:
lenient-trueif lenient,falseotherwise
-
-