com.sun.syndication.io.impl

Class DateParser

public class DateParser extends Object

A helper class that parses Dates out of Strings with date time in RFC822 and W3CDateTime formats plus the variants Atom (0.3) and RSS (0.9, 0.91, 0.92, 0.93, 0.94, 1.0 and 2.0) specificators added to those formats.

It uses the JDK java.text.SimpleDateFormat class attemtping the parse using a mask for each one of the possible formats.

Author: Alejandro Abdelnur

Field Summary
static String[]ADDITIONAL_MASKS
static String[]masks
The masks used to validate and parse the input to this Atom date.
static String[]RFC822_MASKS
static String[]W3CDATETIME_MASKS
Constructor Summary
DateParser()
Private constructor to avoid DateParser instances creation.
Method Summary
static StringformatRFC822(Date date)
create a RFC822 representation of a date.
static StringformatW3CDateTime(Date date)
create a W3C Date Time representation of a date.
static DateparseDate(String sDate)
Parses a Date out of a String with a date in W3C date-time format or in a RFC822 format.
static DateparseRFC822(String sDate)
Parses a Date out of a String with a date in RFC822 format.
static DateparseUsingMask(String[] masks, String sDate)
Parses a Date out of a string using an array of masks.
static DateparseW3CDateTime(String sDate)
Parses a Date out of a String with a date in W3C date-time format.

Field Detail

ADDITIONAL_MASKS

private static String[] ADDITIONAL_MASKS

masks

private static final String[] masks
The masks used to validate and parse the input to this Atom date. These are a lot more forgiving than what the Atom spec allows. The forms that are invalid according to the spec are indicated.

RFC822_MASKS

private static final String[] RFC822_MASKS

W3CDATETIME_MASKS

private static final String[] W3CDATETIME_MASKS

Constructor Detail

DateParser

private DateParser()
Private constructor to avoid DateParser instances creation.

Method Detail

formatRFC822

public static String formatRFC822(Date date)
create a RFC822 representation of a date.

Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element.

Parameters: date Date to parse

Returns: the RFC822 represented by the given Date It returns null if it was not possible to parse the date.

formatW3CDateTime

public static String formatW3CDateTime(Date date)
create a W3C Date Time representation of a date.

Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element.

Parameters: date Date to parse

Returns: the W3C Date Time represented by the given Date It returns null if it was not possible to parse the date.

parseDate

public static Date parseDate(String sDate)
Parses a Date out of a String with a date in W3C date-time format or in a RFC822 format.

Parameters: sDate string to parse for a date.

Returns: the Date represented by the given W3C date-time string. It returns null if it was not possible to parse the given string into a Date.

parseRFC822

public static Date parseRFC822(String sDate)
Parses a Date out of a String with a date in RFC822 format.

It parsers the following formats:

Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element.

Parameters: sDate string to parse for a date.

Returns: the Date represented by the given RFC822 string. It returns null if it was not possible to parse the given string into a Date.

parseUsingMask

private static Date parseUsingMask(String[] masks, String sDate)
Parses a Date out of a string using an array of masks.

It uses the masks in order until one of them succedes or all fail.

Parameters: masks array of masks to use for parsing the string sDate string to parse for a date.

Returns: the Date represented by the given string using one of the given masks. It returns null if it was not possible to parse the the string with any of the masks.

parseW3CDateTime

public static Date parseW3CDateTime(String sDate)
Parses a Date out of a String with a date in W3C date-time format.

It parsers the following formats:

Refer to the java.text.SimpleDateFormat javadocs for details on the format of each element.

Parameters: sDate string to parse for a date.

Returns: the Date represented by the given W3C date-time string. It returns null if it was not possible to parse the given string into a Date.

Copyright © Sun Microsystems. All Rights Reserved.