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 aSimpleDateFormat
class to parse and formatjava.util.Date
objects. If no pattern is set,DateFormat.getInstance()
is used to create a default date format. By default,lenient
is false.- Since:
- 2.1.0
- See Also:
Date
,DateFormat
,SimpleDateFormat
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
lenient
protected java.lang.String
pattern
protected java.util.TimeZone
timeZone
-
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.DateFormat
createDateFormat()
Creates theDateFormat
to use to parse and format the field value.protected java.text.DateFormat
createDefaultDateFormat()
Creates a default date format when no pattern is set.protected java.lang.String
formatDate(java.util.Date date)
Converts aDate
to text.java.lang.String
getPattern()
Returns the date pattern used by theSimpleDateFormat
.java.util.TimeZone
getTimeZone()
Returns the configuredTimeZone
or null if not set.java.lang.String
getTimeZoneId()
Returns the time zone used to interpret dates, ornull
if the default time zone will be used.boolean
isLenient()
Returns whether theSimpleDateFormat
is lenient.DateTypeHandlerSupport
newInstance(java.util.Properties properties)
Creates a customized instance of this type handler.protected java.util.Date
parseDate(java.lang.String text)
Parses text into aDate
.void
setLenient(boolean lenient)
Sets whether theSimpleDateFormat
is lenient.void
setPattern(java.lang.String pattern)
Sets the date pattern used by theSimpleDateFormat
.void
setTimeZoneId(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 TypeConversionException
Parses 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 aDate
to text.- Parameters:
date
- theDate
to convert- Returns:
- the formatted text
-
createDateFormat
protected java.text.DateFormat createDateFormat()
Creates theDateFormat
to use to parse and format the field value.- Returns:
- the
DateFormat
for 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:ConfigurableTypeHandler
Creates a customized instance of this type handler.- Specified by:
newInstance
in 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.IllegalArgumentException
Sets 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, ornull
if the default time zone will be used.- Returns:
- the time zone ID
- See Also:
TimeZone
-
getTimeZone
public java.util.TimeZone getTimeZone()
Returns the configuredTimeZone
or null if not set.- Returns:
- the
TimeZone
-
isLenient
public boolean isLenient()
Returns whether theSimpleDateFormat
is lenient.- Returns:
true
if lenient,false
otherwise
-
setLenient
public void setLenient(boolean lenient)
Sets whether theSimpleDateFormat
is lenient.- Parameters:
lenient
-true
if lenient,false
otherwise
-
-