Top Description Inners Fields Constructors Methods
net.fortuna.ical4j.model

public final Class CalendarDateFormatFactory

extends Object
Class Inheritance
Annotations
@Deprecated
Imports
org.slf4j.Logger, .LoggerFactory, java.text.FieldPosition, .NumberFormat, .ParsePosition, .SimpleDateFormat, java.util.Date, .GregorianCalendar, .TimeZone

Deprecated

adoption of the new date/time API means formatting is now supported via java.time.format.DateTimeFormatter

$Id$ [06-Apr-2004]

Creates DateFormat objects optimized for common iCalendar date patterns.

Author
Dave Nault [email protected]
See Also
getInstance(String)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private abstract static class
private static class
private static class
CalendarDateFormatFactory.DateTimeFormat

A custom date-time formatter.

private static class

Field Summary

Modifier and TypeField and Description
private static final String
private static final String
private static final String
private static final Logger
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
private
CalendarDateFormatFactory()

Constructor made private to enforce static nature.

Method Summary

Modifier and TypeMethod and Description
private static void
appendPadded(StringBuffer toAppendTo, int value, int fieldWidth)

public static DateFormat

Returns:

an optimized DateFormat instance if possible, otherwise a normal SimpleDateFormat instance
getInstance
(String
a SimpleDateFormat-compatible pattern
pattern
)

Returns DateFormat objects optimized for common iCalendar date patterns.

private static Calendar
makeCalendar(boolean lenient, TimeZone timeZone, int year, int zeroBasedMonth, int day, int hour, int minutes, int seconds)

private static Calendar
makeCalendar(boolean lenient, TimeZone timeZone, int year, int month, int day)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DATE_PATTERNback to summary
private static final String DATE_PATTERN
DATETIME_PATTERNback to summary
private static final String DATETIME_PATTERN
DATETIME_UTC_PATTERNback to summary
private static final String DATETIME_UTC_PATTERN
LOGback to summary
private static final Logger LOG
TIME_PATTERNback to summary
private static final String TIME_PATTERN
TIME_UTC_PATTERNback to summary
private static final String TIME_UTC_PATTERN

Constructor Detail

CalendarDateFormatFactoryback to summary
private CalendarDateFormatFactory()

Constructor made private to enforce static nature.

Method Detail

appendPaddedback to summary
private static void appendPadded(StringBuffer toAppendTo, int value, int fieldWidth)
getInstanceback to summary
public static DateFormat getInstance(String pattern)

Returns DateFormat objects optimized for common iCalendar date patterns. The DateFormats are *not* thread safe. Attempts to get or set the Calendar or NumberFormat of an optimized DateFormat will result in an UnsupportedOperation exception being thrown.

Parameters
pattern:String

a SimpleDateFormat-compatible pattern

Returns:DateFormat

an optimized DateFormat instance if possible, otherwise a normal SimpleDateFormat instance

makeCalendarback to summary
private static Calendar makeCalendar(boolean lenient, TimeZone timeZone, int year, int zeroBasedMonth, int day, int hour, int minutes, int seconds)
makeCalendarback to summary
private static Calendar makeCalendar(boolean lenient, TimeZone timeZone, int year, int month, int day)
net.fortuna.ical4j.model back to summary

private abstract Class CalendarDateFormatFactory.CalendarDateFormat

extends DateFormat
Class Inheritance
Known Direct Subclasses
net.fortuna.ical4j.model.CalendarDateFormatFactory.DateTimeFormat, net.fortuna.ical4j.model.CalendarDateFormatFactory.DateFormat, net.fortuna.ical4j.model.CalendarDateFormatFactory.TimeFormat

Field Summary

Modifier and TypeField and Description
private static final TimeZone
private boolean
private final String
private static final long
private TimeZone
Inherited from java.text.DateFormat:
AM_PM_FIELDcalendarDATE_FIELDDAY_OF_WEEK_FIELDDAY_OF_WEEK_IN_MONTH_FIELDDAY_OF_YEAR_FIELDDEFAULTERA_FIELDFULLHOUR0_FIELDHOUR1_FIELDHOUR_OF_DAY0_FIELDHOUR_OF_DAY1_FIELDLONGMEDIUMMILLISECOND_FIELDMINUTE_FIELDMONTH_FIELDnumberFormatSECOND_FIELDSHORTTIMEZONE_FIELDWEEK_OF_MONTH_FIELDWEEK_OF_YEAR_FIELDYEAR_FIELD

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object
clone()

Overrides java.text.DateFormat.clone.

Overrides Cloneable

public boolean
equals(Object
object to be compared for equality
o
)

Overrides java.text.DateFormat.equals.

Compares the specified object with this DateFormat for equality.

public Calendar
getCalendar()

Overrides java.text.DateFormat.getCalendar.

Gets the calendar associated with this date/time formatter.

public NumberFormat
getNumberFormat()

Overrides java.text.DateFormat.getNumberFormat.

Gets the number formatter which this date/time formatter uses to format and parse a time.

public TimeZone
getTimeZone()

Overrides java.text.DateFormat.getTimeZone.

Gets the time zone.

public int
hashCode()

Overrides java.text.DateFormat.hashCode.

Returns the hash code for this DateFormat.

public boolean
isLenient()

Overrides java.text.DateFormat.isLenient.

Tell whether date/time parsing is to be lenient.

public void
setCalendar(Calendar
the new Calendar to be used by the date format
c
)

Overrides java.text.DateFormat.setCalendar.

Set the calendar to be used by this date format.

public void
setLenient(boolean
when true, parsing is lenient
lenient
)

Overrides java.text.DateFormat.setLenient.

Specify whether or not date/time parsing is to be lenient.

public void
setNumberFormat(NumberFormat
the given new NumberFormat.
n
)

Overrides java.text.DateFormat.setNumberFormat.

Allows you to set the number formatter.

public void
setTimeZone(TimeZone
the given new time zone.
tz
)

Overrides java.text.DateFormat.setTimeZone.

Sets the time zone for the calendar of this DateFormat object.

Inherited from java.text.DateFormat:
formatformatformatgetAvailableLocalesgetDateInstancegetDateInstancegetDateInstancegetDateTimeInstancegetDateTimeInstancegetDateTimeInstancegetInstancegetTimeInstancegetTimeInstancegetTimeInstanceparseparseparseObject

Field Detail

DEFAULT_TIME_ZONEback to summary
private static final TimeZone DEFAULT_TIME_ZONE
lenientback to summary
private boolean lenient
patternback to summary
private final String pattern
serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.text.DateFormat.serialVersionUID.

timeZoneback to summary
private TimeZone timeZone

Constructor Detail

CalendarDateFormatback to summary
public CalendarDateFormat(String pattern)

Method Detail

cloneback to summary
public Object clone()

Overrides java.text.DateFormat.clone.

Doc from java.text.DateFormat.clone.

Overrides Cloneable

Returns:Object

Doc from java.text.Format.clone.

a clone of this instance.

Annotations
@Override
equalsback to summary
public boolean equals(Object o)

Overrides java.text.DateFormat.equals.

Doc from java.text.DateFormat.equals.

Compares the specified object with this DateFormat for equality. Returns true if the object is also a DateFormat and the two formats would format any value the same.

Parameters
o:Object

object to be compared for equality

Returns:boolean

true if the specified object is equal to this DateFormat

Annotations
@Override
getCalendarback to summary
public Calendar getCalendar()

Overrides java.text.DateFormat.getCalendar.

Doc from java.text.DateFormat.getCalendar.

Gets the calendar associated with this date/time formatter.

Returns:Calendar

the calendar associated with this date/time formatter.

Annotations
@Override
getNumberFormatback to summary
public NumberFormat getNumberFormat()

Overrides java.text.DateFormat.getNumberFormat.

Doc from java.text.DateFormat.getNumberFormat.

Gets the number formatter which this date/time formatter uses to format and parse a time.

Returns:NumberFormat

the number formatter which this date/time formatter uses.

Annotations
@Override
getTimeZoneback to summary
public TimeZone getTimeZone()

Overrides java.text.DateFormat.getTimeZone.

Doc from java.text.DateFormat.getTimeZone.

Gets the time zone. This method is equivalent to the following call.

getCalendar().getTimeZone();
getCalendar().getTimeZone();
Returns:TimeZone

the time zone associated with the calendar of DateFormat.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.text.DateFormat.hashCode.

Doc from java.text.DateFormat.hashCode.

Returns the hash code for this DateFormat.

Returns:int

the hash code for this DateFormat

Annotations
@Override
isLenientback to summary
public boolean isLenient()

Overrides java.text.DateFormat.isLenient.

Doc from java.text.DateFormat.isLenient.

Tell whether date/time parsing is to be lenient. This method is equivalent to the following call.

getCalendar().isLenient();
getCalendar().isLenient();
Returns:boolean

true if the calendar is lenient; false otherwise.

Annotations
@Override
setCalendarback to summary
public void setCalendar(Calendar c)

Overrides java.text.DateFormat.setCalendar.

Doc from java.text.DateFormat.setCalendar.

Set the calendar to be used by this date format. Initially, the default calendar for the specified or default locale is used.

Any TimeZone and leniency values that have previously been set are overwritten by newCalendar's values.

Parameters
c:Calendar

the new Calendar to be used by the date format

Annotations
@Override
setLenientback to summary
public void setLenient(boolean lenient)

Overrides java.text.DateFormat.setLenient.

Doc from java.text.DateFormat.setLenient.

Specify whether or not date/time parsing is to be lenient. With lenient parsing, the parser may use heuristics to interpret inputs that do not precisely match this object's format. With strict parsing, inputs must match this object's format.

This method is equivalent to the following call.

getCalendar().setLenient(lenient);
getCalendar().setLenient(lenient);

This leniency value is overwritten by a call to setCalendar().

Parameters
lenient:boolean

when true, parsing is lenient

Annotations
@Override
setNumberFormatback to summary
public void setNumberFormat(NumberFormat n)

Overrides java.text.DateFormat.setNumberFormat.

Doc from java.text.DateFormat.setNumberFormat.

Allows you to set the number formatter.

Parameters
n:NumberFormat

the given new NumberFormat.

Annotations
@Override
setTimeZoneback to summary
public void setTimeZone(TimeZone tz)

Overrides java.text.DateFormat.setTimeZone.

Doc from java.text.DateFormat.setTimeZone.

Sets the time zone for the calendar of this DateFormat object. This method is equivalent to the following call.

getCalendar().setTimeZone(zone);
getCalendar().setTimeZone(zone);

The TimeZone set by this method is overwritten by a setCalendar call.

The TimeZone set by this method may be overwritten as a result of a call to the parse method.

Parameters
tz:TimeZone

the given new time zone.

Annotations
@Override
net.fortuna.ical4j.model back to summary

private Class CalendarDateFormatFactory.DateFormat

extends CalendarDateFormat
Class Inheritance

Custom date formatter. Parses and formats this pattern:

yyyyMMdd

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
public
DateFormat(String pattern)

Method Summary

Modifier and TypeMethod and Description
public StringBuffer
format(Date
a Date to be formatted into a date-time string.
date
,
StringBuffer
the string buffer for the returning date-time string.
toAppendTo
,
FieldPosition
keeps track on the position of the field within the returned string. For example, given a date-time text "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition is DateFormat#YEAR_FIELD, the begin index and end index of fieldPosition will be set to 0 and 4, respectively. Notice that if the same date-time field appears more than once in a pattern, the fieldPosition will be set for the first occurrence of that date-time field. For instance, formatting a Date to the date-time string "1 PM PDT (Pacific Daylight Time)" using the pattern "h a z (zzzz)" and the alignment field DateFormat#TIMEZONE_FIELD, the begin index and end index of fieldPosition will be set to 5 and 8, respectively, for the first occurrence of the timezone pattern character 'z'.
fieldPosition
)

Implements abstract java.text.DateFormat.format.

Formats a Date into a date-time string.

public Date
parse(String
The date/time string to be parsed
source
,
ParsePosition
On input, the position at which to start parsing; on output, the position at which parsing terminated, or the start position if the parse failed.
pos
)

Implements abstract java.text.DateFormat.parse.

Parse a date/time string according to the given parse position.

Inherited from net.fortuna.ical4j.model.CalendarDateFormatFactory.CalendarDateFormat:
cloneequalsgetCalendargetNumberFormatgetTimeZonehashCodeisLenientsetCalendarsetLenientsetNumberFormatsetTimeZone

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides net.fortuna.ical4j.model.CalendarDateFormatFactory.CalendarDateFormat.serialVersionUID.

Constructor Detail

DateFormatback to summary
public DateFormat(String pattern)

Method Detail

formatback to summary
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition)

Implements abstract java.text.DateFormat.format.

Doc from java.text.DateFormat.format.

Formats a Date into a date-time string. The formatted string is appended to the given StringBuffer.

Parameters
date:Date

a Date to be formatted into a date-time string.

toAppendTo:StringBuffer

the string buffer for the returning date-time string.

fieldPosition:FieldPosition

keeps track on the position of the field within the returned string. For example, given a date-time text "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition is DateFormat#YEAR_FIELD, the begin index and end index of fieldPosition will be set to 0 and 4, respectively. Notice that if the same date-time field appears more than once in a pattern, the fieldPosition will be set for the first occurrence of that date-time field. For instance, formatting a Date to the date-time string "1 PM PDT (Pacific Daylight Time)" using the pattern "h a z (zzzz)" and the alignment field DateFormat#TIMEZONE_FIELD, the begin index and end index of fieldPosition will be set to 5 and 8, respectively, for the first occurrence of the timezone pattern character 'z'.

Returns:StringBuffer

the string buffer passed in as toAppendTo, with formatted text appended.

Annotations
@Override
parseback to summary
public Date parse(String source, ParsePosition pos)

Implements abstract java.text.DateFormat.parse.

Doc from java.text.DateFormat.parse.

Parse a date/time string according to the given parse position. For example, if this has the pattern "M/d/yy h:m a, z", then a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date that is equivalent to Date(837039900000L).

By default, parsing is lenient: If the input is not in the form used by this object's format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).

This parsing operation uses the calendar to produce a Date. As a result, the calendar's date-time fields and the TimeZone value may have been overwritten, depending on subclass implementations. Any TimeZone value that has previously been set by a call to setTimeZone may need to be restored for further operations.

Parameters
source:String

The date/time string to be parsed

pos:ParsePosition

On input, the position at which to start parsing; on output, the position at which parsing terminated, or the start position if the parse failed.

Returns:Date

A Date, or null if the input could not be parsed

Annotations
@Override
net.fortuna.ical4j.model back to summary

private Class CalendarDateFormatFactory.DateTimeFormat

extends CalendarDateFormat
Class Inheritance

A custom date-time formatter. Parses and formats these patterns:

yyyyMMdd'T'HHmmss
yyyyMMdd'T'HHmmss'Z'

Field Summary

Modifier and TypeField and Description
pack-priv final boolean
private static final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public StringBuffer
format(Date
a Date to be formatted into a date-time string.
date
,
StringBuffer
the string buffer for the returning date-time string.
toAppendTo
,
FieldPosition
keeps track on the position of the field within the returned string. For example, given a date-time text "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition is DateFormat#YEAR_FIELD, the begin index and end index of fieldPosition will be set to 0 and 4, respectively. Notice that if the same date-time field appears more than once in a pattern, the fieldPosition will be set for the first occurrence of that date-time field. For instance, formatting a Date to the date-time string "1 PM PDT (Pacific Daylight Time)" using the pattern "h a z (zzzz)" and the alignment field DateFormat#TIMEZONE_FIELD, the begin index and end index of fieldPosition will be set to 5 and 8, respectively, for the first occurrence of the timezone pattern character 'z'.
fieldPosition
)

Implements abstract java.text.DateFormat.format.

Formats a Date into a date-time string.

public Date
parse(String
The date/time string to be parsed
source
,
ParsePosition
On input, the position at which to start parsing; on output, the position at which parsing terminated, or the start position if the parse failed.
pos
)

Implements abstract java.text.DateFormat.parse.

Parse a date/time string according to the given parse position.

Inherited from net.fortuna.ical4j.model.CalendarDateFormatFactory.CalendarDateFormat:
cloneequalsgetCalendargetNumberFormatgetTimeZonehashCodeisLenientsetCalendarsetLenientsetNumberFormatsetTimeZone

Field Detail

patternEndsWithZback to summary
pack-priv final boolean patternEndsWithZ
serialVersionUIDback to summary
private static final long serialVersionUID

Hides net.fortuna.ical4j.model.CalendarDateFormatFactory.CalendarDateFormat.serialVersionUID.

Constructor Detail

DateTimeFormatback to summary
public DateTimeFormat(String pattern)

Method Detail

formatback to summary
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition)

Implements abstract java.text.DateFormat.format.

Doc from java.text.DateFormat.format.

Formats a Date into a date-time string. The formatted string is appended to the given StringBuffer.

Parameters
date:Date

a Date to be formatted into a date-time string.

toAppendTo:StringBuffer

the string buffer for the returning date-time string.

fieldPosition:FieldPosition

keeps track on the position of the field within the returned string. For example, given a date-time text "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition is DateFormat#YEAR_FIELD, the begin index and end index of fieldPosition will be set to 0 and 4, respectively. Notice that if the same date-time field appears more than once in a pattern, the fieldPosition will be set for the first occurrence of that date-time field. For instance, formatting a Date to the date-time string "1 PM PDT (Pacific Daylight Time)" using the pattern "h a z (zzzz)" and the alignment field DateFormat#TIMEZONE_FIELD, the begin index and end index of fieldPosition will be set to 5 and 8, respectively, for the first occurrence of the timezone pattern character 'z'.

Returns:StringBuffer

the string buffer passed in as toAppendTo, with formatted text appended.

Annotations
@Override
parseback to summary
public Date parse(String source, ParsePosition pos)

Implements abstract java.text.DateFormat.parse.

Doc from java.text.DateFormat.parse.

Parse a date/time string according to the given parse position. For example, if this has the pattern "M/d/yy h:m a, z", then a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date that is equivalent to Date(837039900000L).

By default, parsing is lenient: If the input is not in the form used by this object's format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).

This parsing operation uses the calendar to produce a Date. As a result, the calendar's date-time fields and the TimeZone value may have been overwritten, depending on subclass implementations. Any TimeZone value that has previously been set by a call to setTimeZone may need to be restored for further operations.

Parameters
source:String

The date/time string to be parsed

pos:ParsePosition

On input, the position at which to start parsing; on output, the position at which parsing terminated, or the start position if the parse failed.

Returns:Date

A Date, or null if the input could not be parsed

Annotations
@Override
net.fortuna.ical4j.model back to summary

private Class CalendarDateFormatFactory.TimeFormat

extends CalendarDateFormat
Class Inheritance

Custom time formatter. Parses and formats these patterns:

HHmmss
HHmmss'Z'

Field Summary

Modifier and TypeField and Description
pack-priv final boolean
private static final long

Constructor Summary

AccessConstructor and Description
public
TimeFormat(String pattern)

Method Summary

Modifier and TypeMethod and Description
public StringBuffer
format(Date
a Date to be formatted into a date-time string.
date
,
StringBuffer
the string buffer for the returning date-time string.
toAppendTo
,
FieldPosition
keeps track on the position of the field within the returned string. For example, given a date-time text "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition is DateFormat#YEAR_FIELD, the begin index and end index of fieldPosition will be set to 0 and 4, respectively. Notice that if the same date-time field appears more than once in a pattern, the fieldPosition will be set for the first occurrence of that date-time field. For instance, formatting a Date to the date-time string "1 PM PDT (Pacific Daylight Time)" using the pattern "h a z (zzzz)" and the alignment field DateFormat#TIMEZONE_FIELD, the begin index and end index of fieldPosition will be set to 5 and 8, respectively, for the first occurrence of the timezone pattern character 'z'.
fieldPosition
)

Implements abstract java.text.DateFormat.format.

Formats a Date into a date-time string.

public Date
parse(String
The date/time string to be parsed
source
,
ParsePosition
On input, the position at which to start parsing; on output, the position at which parsing terminated, or the start position if the parse failed.
pos
)

Implements abstract java.text.DateFormat.parse.

Parse a date/time string according to the given parse position.

Inherited from net.fortuna.ical4j.model.CalendarDateFormatFactory.CalendarDateFormat:
cloneequalsgetCalendargetNumberFormatgetTimeZonehashCodeisLenientsetCalendarsetLenientsetNumberFormatsetTimeZone

Field Detail

patternEndsWithZback to summary
pack-priv final boolean patternEndsWithZ
serialVersionUIDback to summary
private static final long serialVersionUID

Hides net.fortuna.ical4j.model.CalendarDateFormatFactory.CalendarDateFormat.serialVersionUID.

Constructor Detail

TimeFormatback to summary
public TimeFormat(String pattern)

Method Detail

formatback to summary
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition)

Implements abstract java.text.DateFormat.format.

Doc from java.text.DateFormat.format.

Formats a Date into a date-time string. The formatted string is appended to the given StringBuffer.

Parameters
date:Date

a Date to be formatted into a date-time string.

toAppendTo:StringBuffer

the string buffer for the returning date-time string.

fieldPosition:FieldPosition

keeps track on the position of the field within the returned string. For example, given a date-time text "1996.07.10 AD at 15:08:56 PDT", if the given fieldPosition is DateFormat#YEAR_FIELD, the begin index and end index of fieldPosition will be set to 0 and 4, respectively. Notice that if the same date-time field appears more than once in a pattern, the fieldPosition will be set for the first occurrence of that date-time field. For instance, formatting a Date to the date-time string "1 PM PDT (Pacific Daylight Time)" using the pattern "h a z (zzzz)" and the alignment field DateFormat#TIMEZONE_FIELD, the begin index and end index of fieldPosition will be set to 5 and 8, respectively, for the first occurrence of the timezone pattern character 'z'.

Returns:StringBuffer

the string buffer passed in as toAppendTo, with formatted text appended.

Annotations
@Override
parseback to summary
public Date parse(String source, ParsePosition pos)

Implements abstract java.text.DateFormat.parse.

Doc from java.text.DateFormat.parse.

Parse a date/time string according to the given parse position. For example, if this has the pattern "M/d/yy h:m a, z", then a time text "07/10/96 4:5 PM, PDT" will be parsed into a Date that is equivalent to Date(837039900000L).

By default, parsing is lenient: If the input is not in the form used by this object's format method but can still be parsed as a date, then the parse succeeds. Clients may insist on strict adherence to the format by calling setLenient(false).

This parsing operation uses the calendar to produce a Date. As a result, the calendar's date-time fields and the TimeZone value may have been overwritten, depending on subclass implementations. Any TimeZone value that has previously been set by a call to setTimeZone may need to be restored for further operations.

Parameters
source:String

The date/time string to be parsed

pos:ParsePosition

On input, the position at which to start parsing; on output, the position at which parsing terminated, or the start position if the parse failed.

Returns:Date

A Date, or null if the input could not be parsed

Annotations
@Override