Joda Time API

org.joda.time
Class TimePeriodFormat

java.lang.Object
  |
  +--java.text.Format
        |
        +--org.joda.time.TimePeriodFormat
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public final class TimePeriodFormat
extends java.text.Format

TimePeriodFormat provides formatting and parsing capabilities to the TimePeriod class. The parse method with return TimePeriod Objects.

The ISO Time Period specification defines several formats for a time period. These are defined as constants in this class. There is a limted set of valid format defined in the specification, for this reason the constructor of this class is private and users must use one of the predefined format constants to format and parse strings.

A Time Period is formatted according to the data that was used to create it. These can be off the forms:

The duration component is always preceded with a 'P' and when two components are required they are seperated with a solidus, '/'. Where a components is a date it will be formatted using the respective format in DateTimeFormat.

Format Types

The format types for the duration component can be broken up into two main formats with variations within those formats.

Standard Basic takes the form: PnYnMnDTnHnMnS where n is the value of the following component designator.

Standard Extended takes the same form except when a date component exists the date is formated in the EXTENDED DateTime form as opposed to the BASIC form.

There are variations in the above two formats to either, allow components that are zero to be ommited, force components that are 0 to be included or represent the period using weeks only, i.e. PnW

Alternative Basic takes the form: PYYYYMMDDThhmmss.

Alternative Extended takes the form: PYYYY-MM-DDThh:mm:ss and uses the EXTENDED DateTime format for format date components.

The two alternative formats have the variations to allow or deny truncating of components equalling zero.

Author:
Sean Geoghegan
See Also:
Serialized Form

Field Summary
static TimePeriodFormat ISO_ALTERNATIVE_BASIC_NO_TRUNCATE_FORMAT
          Formatter for the ISO Alternative Basic Time Period format that does not truncate zero components.
static TimePeriodFormat ISO_ALTERNATIVE_BASIC_TRUNCATE_FORMAT
          Formatter for the ISO Alternative Basic Time Period format that truncates zero components.
static TimePeriodFormat ISO_ALTERNATIVE_EXTENDED_NO_TRUNCATE_FORMAT
          Formatter for the ISO Alternative Extended Time Period format that does not truncate zero components.
static TimePeriodFormat ISO_ALTERNATIVE_EXTENDED_TRUNCATE_FORMAT
          Formatter for the ISO Alternative Extended Time Period format that truncates zero components.
static TimePeriodFormat ISO_STANDARD_BASIC_FORMAT
          Formatter for the ISO Standard Basic Time Period format that does not ommit components that are equal to zero.
static TimePeriodFormat ISO_STANDARD_BASIC_WEEKS_ONLY_FORMAT
          Formatter for the ISO Standard Basic Time Period format that formats using weeks only.
static TimePeriodFormat ISO_STANDARD_BASIC_ZERO_OMIT_FORMAT
          Formatter for the ISO Standard Basic Time Period format that ommits components that are equal to zero.
static TimePeriodFormat ISO_STANDARD_EXTENDED_FORMAT
          Formatter for the ISO Standard Extended Time Period format that ommits components that are equal to zero.
static TimePeriodFormat ISO_STANDARD_EXTENDED_WEEKS_ONLY_FORMAT
          Formatter for the ISO Standard Extended Time Period format that formats using weeks only.
static TimePeriodFormat ISO_STANDARD_EXTENDED_ZERO_OMIT_FORMAT
          Formatter for the ISO Standard Extended Time Period format that ommits components that are equal to zero.
 
Method Summary
 java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer buffer, java.text.FieldPosition pos)
          Formats obj in accordance with this formatter type.
 java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition status)
          Parses the specified string to a TimePeriod Object.
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ISO_STANDARD_BASIC_ZERO_OMIT_FORMAT

public static final TimePeriodFormat ISO_STANDARD_BASIC_ZERO_OMIT_FORMAT
Formatter for the ISO Standard Basic Time Period format that ommits components that are equal to zero.


ISO_STANDARD_EXTENDED_ZERO_OMIT_FORMAT

public static final TimePeriodFormat ISO_STANDARD_EXTENDED_ZERO_OMIT_FORMAT
Formatter for the ISO Standard Extended Time Period format that ommits components that are equal to zero.


ISO_STANDARD_BASIC_FORMAT

public static final TimePeriodFormat ISO_STANDARD_BASIC_FORMAT
Formatter for the ISO Standard Basic Time Period format that does not ommit components that are equal to zero.


ISO_STANDARD_EXTENDED_FORMAT

public static final TimePeriodFormat ISO_STANDARD_EXTENDED_FORMAT
Formatter for the ISO Standard Extended Time Period format that ommits components that are equal to zero.


ISO_STANDARD_BASIC_WEEKS_ONLY_FORMAT

public static final TimePeriodFormat ISO_STANDARD_BASIC_WEEKS_ONLY_FORMAT
Formatter for the ISO Standard Basic Time Period format that formats using weeks only.


ISO_STANDARD_EXTENDED_WEEKS_ONLY_FORMAT

public static final TimePeriodFormat ISO_STANDARD_EXTENDED_WEEKS_ONLY_FORMAT
Formatter for the ISO Standard Extended Time Period format that formats using weeks only.


ISO_ALTERNATIVE_BASIC_TRUNCATE_FORMAT

public static final TimePeriodFormat ISO_ALTERNATIVE_BASIC_TRUNCATE_FORMAT
Formatter for the ISO Alternative Basic Time Period format that truncates zero components.


ISO_ALTERNATIVE_EXTENDED_TRUNCATE_FORMAT

public static final TimePeriodFormat ISO_ALTERNATIVE_EXTENDED_TRUNCATE_FORMAT
Formatter for the ISO Alternative Extended Time Period format that truncates zero components.


ISO_ALTERNATIVE_BASIC_NO_TRUNCATE_FORMAT

public static final TimePeriodFormat ISO_ALTERNATIVE_BASIC_NO_TRUNCATE_FORMAT
Formatter for the ISO Alternative Basic Time Period format that does not truncate zero components.


ISO_ALTERNATIVE_EXTENDED_NO_TRUNCATE_FORMAT

public static final TimePeriodFormat ISO_ALTERNATIVE_EXTENDED_NO_TRUNCATE_FORMAT
Formatter for the ISO Alternative Extended Time Period format that does not truncate zero components.

Method Detail

format

public java.lang.StringBuffer format(java.lang.Object obj,
                                     java.lang.StringBuffer buffer,
                                     java.text.FieldPosition pos)
Formats obj in accordance with this formatter type.

Specified by:
format in class java.text.Format
Parameters:
obj - the object to format
buffer - the StringBuffer to append the output to
pos - the position to start at
Returns:
the StringBuffer object passed as an argument
Throws:
java.lang.IllegalArgumentException - if this formatter doesnt handle the type of the Object obj.
See Also:
Format.format(Object,StringBuffer,FieldPosition)

parseObject

public java.lang.Object parseObject(java.lang.String source,
                                    java.text.ParsePosition status)
Parses the specified string to a TimePeriod Object. This method attempts to parse the string according to the rules of the format represented by this object.

Specified by:
parseObject in class java.text.Format
Parameters:
source - the string to parse to a TimePeriod
status - object that hold index and error index information
Returns:
a new TimePeriod Object based on this string or null if an error occured and the string format does not match this format.
See Also:
Format.parseObject(String,ParsePosition)

Joda Time API

Copyright © 2001-2003 Stephen Colebourne. All Rights Reserved.