com.skaringa.util
Class ISO8601DateTimeFormat

java.lang.Object
  extended by java.text.Format
      extended by java.text.DateFormat
          extended by com.skaringa.util.ISO8601DateTimeFormat
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
ISO8601DateFormat

public class ISO8601DateTimeFormat
extends java.text.DateFormat

Format and parse an ISO 8601 DateTimeFormat used in XML documents. This lexical representation is the ISO 8601 extended format CCYY-MM-DDThh:mm:ss where "CC" represents the century, "YY" the year, "MM" the month and "DD" the day, preceded by an optional leading "-" sign to indicate a negative number. If the sign is omitted, "+" is assumed. The letter "T" is the date/time separator and "hh", "mm", "ss" represent hour, minute and second respectively. This representation may be immediately followed by a "Z" to indicate Coordinated Universal Time (UTC) or, to indicate the time zone, i.e. the difference between the local time and Coordinated Universal Time, immediately followed by a sign, + or -, followed by the difference from UTC represented as hh:mm.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.DateFormat
java.text.DateFormat.Field
 
Field Summary
 
Fields inherited from class java.text.DateFormat
AM_PM_FIELD, calendar, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, numberFormat, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD
 
Constructor Summary
ISO8601DateTimeFormat()
          Construct a new ISO8601DateTimeFormat using the default time zone.
ISO8601DateTimeFormat(java.util.TimeZone tz)
          Construct a new ISO8601DateTimeFormat using a specific time zone.
 
Method Summary
protected  void appendInt(java.lang.StringBuffer buf, int value, int length)
          Write an integer value with leading zeros.
 java.lang.StringBuffer format(java.util.Date date, java.lang.StringBuffer sbuf, java.text.FieldPosition fieldPosition)
           
 java.util.Date parse(java.lang.String text, java.text.ParsePosition pos)
           
protected  int parseTZ(int i, java.lang.String text)
          Parse the time zone.
protected  void writeCCYYMM(java.lang.StringBuffer sbuf)
          Write century, year, and months.
protected  void writehhmmss(java.lang.StringBuffer sbuf)
          Write hour, minutes, and seconds.
protected  void writeTZ(java.lang.StringBuffer sbuf)
          Write the time zone string.
 
Methods inherited from class java.text.DateFormat
clone, equals, format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, hashCode, isLenient, parse, parseObject, setCalendar, setLenient, setNumberFormat, setTimeZone
 
Methods inherited from class java.text.Format
format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ISO8601DateTimeFormat

public ISO8601DateTimeFormat()
Construct a new ISO8601DateTimeFormat using the default time zone.


ISO8601DateTimeFormat

public ISO8601DateTimeFormat(java.util.TimeZone tz)
Construct a new ISO8601DateTimeFormat using a specific time zone.

Parameters:
tz - The time zone used to format and parse the date.
Method Detail

parse

public java.util.Date parse(java.lang.String text,
                            java.text.ParsePosition pos)
Specified by:
parse in class java.text.DateFormat
See Also:
DateFormat.parse(String, ParsePosition)

parseTZ

protected final int parseTZ(int i,
                            java.lang.String text)
Parse the time zone.

Parameters:
i - The position to start parsing.
text - The text to parse.
Returns:
The position after parsing has finished.

format

public java.lang.StringBuffer format(java.util.Date date,
                                     java.lang.StringBuffer sbuf,
                                     java.text.FieldPosition fieldPosition)
Specified by:
format in class java.text.DateFormat
See Also:
DateFormat.format(Date, StringBuffer, FieldPosition)

writeTZ

protected final void writeTZ(java.lang.StringBuffer sbuf)
Write the time zone string.

Parameters:
sbuf - The buffer to append the time zone.

writehhmmss

protected final void writehhmmss(java.lang.StringBuffer sbuf)
Write hour, minutes, and seconds.

Parameters:
sbuf - The buffer to append the string.

writeCCYYMM

protected final void writeCCYYMM(java.lang.StringBuffer sbuf)
Write century, year, and months.

Parameters:
sbuf - The buffer to append the string.

appendInt

protected final void appendInt(java.lang.StringBuffer buf,
                               int value,
                               int length)
Write an integer value with leading zeros.

Parameters:
buf - The buffer to append the string.
value - The value to write.
length - The length of the string to write.