Top Description Fields Constructors Methods
com.univocity.parsers.conversions

public Class CalendarConversion

extends ObjectConversion<Calendar>
implements FormattedConversion<SimpleDateFormat>
Class Inheritance
All Implemented Interfaces
com.univocity.parsers.conversions.FormattedConversion
Imports
com.univocity.parsers.common.*, java.text.*, java.util.*

Converts Strings to instances of java.util.Calendar and vice versa.

This class supports multiple date formats. For example, you can define conversions from dates represented by different Strings such as "2001/05/02 and Dec/2013".

The reverse conversion from a Calendar to String (in CalendarConversion#revert(Calendar) will return a formatted String using the date pattern provided in this class constructor

The date patterns must follows the pattern rules of java.text.SimpleDateFormat

Author
Univocity Software Pty Ltd - [email protected]
See Also
java.text.SimpleDateFormat

Field Summary

Modifier and TypeField and Description
private final DateConversion

Constructor Summary

AccessConstructor and Description
public
CalendarConversion(TimeZone
the TimeZone of the given calendar date
timeZone
,
Locale
the Locale that determines how the date mask should be formatted.
locale
,
Calendar
default Calendar value to be returned when the input String is null. Used when ObjectConversion#execute(String) is invoked.
valueIfStringIsNull
,
String
default String value to be returned when a Calendar input is null. Used when CalendarConversion#revert(Calendar) is invoked.
valueIfObjectIsNull
,
String...
list of acceptable date patterns The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).
dateFormats
)

Defines a conversion from String to java.util.Calendar using a sequence of acceptable date patterns.

public
CalendarConversion(Locale
the Locale that determines how the date mask should be formatted.
locale
,
Calendar
default Calendar value to be returned when the input String is null. Used when ObjectConversion#execute(String) is invoked.
valueIfStringIsNull
,
String
default String value to be returned when a Calendar input is null. Used when CalendarConversion#revert(Calendar) is invoked.
valueIfObjectIsNull
,
String...
list of acceptable date patterns The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).
dateFormats
)

Defines a conversion from String to java.util.Calendar using a sequence of acceptable date patterns.

public
CalendarConversion(Calendar
default Calendar value to be returned when the input String is null. Used when ObjectConversion#execute(String) is invoked.
valueIfStringIsNull
,
String
default String value to be returned when a Calendar input is null. Used when CalendarConversion#revert(Calendar) is invoked.
valueIfObjectIsNull
,
String...
list of acceptable date patterns The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).
dateFormats
)

Defines a conversion from String to java.util.Calendar using a sequence of acceptable date patterns.

public
CalendarConversion(Locale
the Locale that determines how the date mask should be formatted.
locale
,
String...
list of acceptable date patterns The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).
dateFormats
)

Defines a conversion from String to java.util.Calendar using a sequence of acceptable date patterns.

public
CalendarConversion(String...
list of acceptable date patterns The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).
dateFormats
)

Defines a conversion from String to java.util.Calendar using a sequence of acceptable date patterns.

Method Summary

Modifier and TypeMethod and Description
protected Calendar

Returns:

the Calendar instance containing the date information represented by the given String, or the value of CalendarConversion#getValueIfStringIsNull() if the String input is null.
fromString
(String
the String containing a formatted date which must be converted to a Calendar
input
)

Implements abstract com.univocity.parsers.conversions.ObjectConversion.fromString.

Converts a formatted date String to an instance of Calendar.
public SimpleDateFormat[]
public String

Returns:

a formatted date String representing the date provided by the given Calendar, or the value of CalendarConversion#getValueIfObjectIsNull() if the Calendar parameter is null.
revert
(Calendar
the Calendar to be converted to a String
input
)

Overrides com.univocity.parsers.conversions.ObjectConversion.revert.

Implements com.univocity.parsers.conversions.Conversion.revert.

Converts Calendar to a formatted date String.
Inherited from com.univocity.parsers.conversions.ObjectConversion:
executefromInputgetValueIfObjectIsNullgetValueIfStringIsNullsetValueIfObjectIsNullsetValueIfStringIsNullundo

Field Detail

dateConversionback to summary
private final DateConversion dateConversion

Constructor Detail

CalendarConversionback to summary
public CalendarConversion(TimeZone timeZone, Locale locale, Calendar valueIfStringIsNull, String valueIfObjectIsNull, String... dateFormats)

Defines a conversion from String to java.util.Calendar using a sequence of acceptable date patterns. This constructor assumes the output of a conversion should be null when input is null

Parameters
timeZone:TimeZone

the TimeZone of the given calendar date

locale:Locale

the Locale that determines how the date mask should be formatted.

valueIfStringIsNull:Calendar

default Calendar value to be returned when the input String is null. Used when ObjectConversion#execute(String) is invoked.

valueIfObjectIsNull:String

default String value to be returned when a Calendar input is null. Used when CalendarConversion#revert(Calendar) is invoked.

dateFormats:String[]

list of acceptable date patterns The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).

CalendarConversionback to summary
public CalendarConversion(Locale locale, Calendar valueIfStringIsNull, String valueIfObjectIsNull, String... dateFormats)

Defines a conversion from String to java.util.Calendar using a sequence of acceptable date patterns. This constructor assumes the output of a conversion should be null when input is null

Parameters
locale:Locale

the Locale that determines how the date mask should be formatted.

valueIfStringIsNull:Calendar

default Calendar value to be returned when the input String is null. Used when ObjectConversion#execute(String) is invoked.

valueIfObjectIsNull:String

default String value to be returned when a Calendar input is null. Used when CalendarConversion#revert(Calendar) is invoked.

dateFormats:String[]

list of acceptable date patterns The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).

CalendarConversionback to summary
public CalendarConversion(Calendar valueIfStringIsNull, String valueIfObjectIsNull, String... dateFormats)

Defines a conversion from String to java.util.Calendar using a sequence of acceptable date patterns. This constructor assumes the output of a conversion should be null when input is null

Parameters
valueIfStringIsNull:Calendar

default Calendar value to be returned when the input String is null. Used when ObjectConversion#execute(String) is invoked.

valueIfObjectIsNull:String

default String value to be returned when a Calendar input is null. Used when CalendarConversion#revert(Calendar) is invoked.

dateFormats:String[]

list of acceptable date patterns The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).

CalendarConversionback to summary
public CalendarConversion(Locale locale, String... dateFormats)

Defines a conversion from String to java.util.Calendar using a sequence of acceptable date patterns. This constructor assumes the output of a conversion should be null when input is null

Parameters
locale:Locale

the Locale that determines how the date mask should be formatted.

dateFormats:String[]

list of acceptable date patterns The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).

CalendarConversionback to summary
public CalendarConversion(String... dateFormats)

Defines a conversion from String to java.util.Calendar using a sequence of acceptable date patterns. This constructor assumes the output of a conversion should be null when input is null

Parameters
dateFormats:String[]

list of acceptable date patterns The first pattern in this sequence will be used to convert a Calendar into a String in CalendarConversion#revert(Calendar).

Method Detail

fromStringback to summary
protected Calendar fromString(String input)

Implements abstract com.univocity.parsers.conversions.ObjectConversion.fromString.

Converts a formatted date String to an instance of Calendar.

The pattern in the formatted date must match one of the date patterns provided in the constructor of this class.

Parameters
input:String

the String containing a formatted date which must be converted to a Calendar

Returns:Calendar

the Calendar instance containing the date information represented by the given String, or the value of CalendarConversion#getValueIfStringIsNull() if the String input is null.

Annotations
@Override
getFormatterObjectsback to summary
public SimpleDateFormat[] getFormatterObjects()

Implements com.univocity.parsers.conversions.FormattedConversion.getFormatterObjects.

Doc from com.univocity.parsers.conversions.FormattedConversion.getFormatterObjects.

Returns the formatter objects

Returns:SimpleDateFormat[]

the formatter objects used to apply formatting to values to generate formatted Strings, and parsing formatted Strings into values

Annotations
@Override
revertback to summary
public String revert(Calendar input)

Overrides com.univocity.parsers.conversions.ObjectConversion.revert.

Implements com.univocity.parsers.conversions.Conversion.revert.

Converts Calendar to a formatted date String.

The pattern used to generate the formatted date is the first date pattern provided in the constructor of this class

Parameters
input:Calendar

the Calendar to be converted to a String

Returns:String

a formatted date String representing the date provided by the given Calendar, or the value of CalendarConversion#getValueIfObjectIsNull() if the Calendar parameter is null.

Annotations
@Override