Class CalendarConversion
java.lang.Object
com.univocity.parsers.conversions.NullConversion<String,Calendar>
com.univocity.parsers.conversions.ObjectConversion<Calendar>
com.univocity.parsers.conversions.CalendarConversion
- All Implemented Interfaces:
Conversion<String,Calendar>, FormattedConversion<SimpleDateFormat>
public class CalendarConversion
extends ObjectConversion<Calendar>
implements FormattedConversion<SimpleDateFormat>
Converts Strings to instances of
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 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 SimpleDateFormat
- Author:
- Univocity Software Pty Ltd - parsers@univocity.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCalendarConversion(String... dateFormats) Defines a conversion from String toCalendarusing a sequence of acceptable date patterns.CalendarConversion(Calendar valueIfStringIsNull, String valueIfObjectIsNull, String... dateFormats) Defines a conversion from String toCalendarusing a sequence of acceptable date patterns.CalendarConversion(Locale locale, String... dateFormats) Defines a conversion from String toCalendarusing a sequence of acceptable date patterns.CalendarConversion(Locale locale, Calendar valueIfStringIsNull, String valueIfObjectIsNull, String... dateFormats) Defines a conversion from String toCalendarusing a sequence of acceptable date patterns.CalendarConversion(TimeZone timeZone, Locale locale, Calendar valueIfStringIsNull, String valueIfObjectIsNull, String... dateFormats) Defines a conversion from String toCalendarusing a sequence of acceptable date patterns. -
Method Summary
Modifier and TypeMethodDescriptionprotected CalendarfromString(String input) Converts a formatted date String to an instance of Calendar.Returns the formatter objectsConverts Calendar to a formatted date String.Methods inherited from class ObjectConversion
execute, fromInput, getValueIfObjectIsNull, getValueIfStringIsNull, setValueIfObjectIsNull, setValueIfStringIsNull, undoMethods inherited from class NullConversion
getValueOnNullInput, getValueOnNullOutput, setValueOnNullInput, setValueOnNullOutput
-
Constructor Details
-
CalendarConversion
public CalendarConversion(TimeZone timeZone, Locale locale, Calendar valueIfStringIsNull, String valueIfObjectIsNull, String... dateFormats) Defines a conversion from String toCalendarusing a sequence of acceptable date patterns. This constructor assumes the output of a conversion should be null when input is null- Parameters:
timeZone- theTimeZoneof the given calendar datelocale- theLocalethat determines how the date mask should be formatted.valueIfStringIsNull- default Calendar value to be returned when the input String is null. Used whenObjectConversion.execute(String)is invoked.valueIfObjectIsNull- default String value to be returned when a Calendar input is null. Used whenrevert(Calendar)is invoked.dateFormats- list of acceptable date patterns The first pattern in this sequence will be used to convert a Calendar into a String inrevert(Calendar).
-
CalendarConversion
public CalendarConversion(Locale locale, Calendar valueIfStringIsNull, String valueIfObjectIsNull, String... dateFormats) Defines a conversion from String toCalendarusing a sequence of acceptable date patterns. This constructor assumes the output of a conversion should be null when input is null- Parameters:
locale- theLocalethat determines how the date mask should be formatted.valueIfStringIsNull- default Calendar value to be returned when the input String is null. Used whenObjectConversion.execute(String)is invoked.valueIfObjectIsNull- default String value to be returned when a Calendar input is null. Used whenrevert(Calendar)is invoked.dateFormats- list of acceptable date patterns The first pattern in this sequence will be used to convert a Calendar into a String inrevert(Calendar).
-
CalendarConversion
public CalendarConversion(Calendar valueIfStringIsNull, String valueIfObjectIsNull, String... dateFormats) Defines a conversion from String toCalendarusing a sequence of acceptable date patterns. This constructor assumes the output of a conversion should be null when input is null- Parameters:
valueIfStringIsNull- default Calendar value to be returned when the input String is null. Used whenObjectConversion.execute(String)is invoked.valueIfObjectIsNull- default String value to be returned when a Calendar input is null. Used whenrevert(Calendar)is invoked.dateFormats- list of acceptable date patterns The first pattern in this sequence will be used to convert a Calendar into a String inrevert(Calendar).
-
CalendarConversion
Defines a conversion from String toCalendarusing a sequence of acceptable date patterns. This constructor assumes the output of a conversion should be null when input is null- Parameters:
locale- theLocalethat determines how the date mask should be formatted.dateFormats- list of acceptable date patterns The first pattern in this sequence will be used to convert a Calendar into a String inrevert(Calendar).
-
CalendarConversion
Defines a conversion from String toCalendarusing a sequence of acceptable date patterns. This constructor assumes the output of a conversion should be null when input is null- Parameters:
dateFormats- list of acceptable date patterns The first pattern in this sequence will be used to convert a Calendar into a String inrevert(Calendar).
-
-
Method Details
-
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
- Specified by:
revertin interfaceConversion<String,Calendar> - Overrides:
revertin classObjectConversion<Calendar>- Parameters:
input- the Calendar to be converted to a String- Returns:
- a formatted date String representing the date provided by the given Calendar, or the value of
ObjectConversion.getValueIfObjectIsNull()if the Calendar parameter is null.
-
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.
- Specified by:
fromStringin classObjectConversion<Calendar>- Parameters:
input- the String containing a formatted date which must be converted to a Calendar- Returns:
- the Calendar instance containing the date information represented by the given String, or the value of
ObjectConversion.getValueIfStringIsNull()if the String input is null.
-
getFormatterObjects
Description copied from interface:FormattedConversionReturns the formatter objects- Specified by:
getFormatterObjectsin interfaceFormattedConversion<SimpleDateFormat>- Returns:
- the formatter objects used to apply formatting to values to generate formatted Strings, and parsing formatted Strings into values
-