pl.edu.agh.cast.data.model.common
Enum SupportedDateFormat

java.lang.Object
  extended by java.lang.Enum<SupportedDateFormat>
      extended by pl.edu.agh.cast.data.model.common.SupportedDateFormat
All Implemented Interfaces:
Serializable, Comparable<SupportedDateFormat>

public enum SupportedDateFormat
extends Enum<SupportedDateFormat>

Defines date formats and provides basic methods for parsing and formating dates.

Supported date formats:

For more details about defining date formats see SimpleDateFormat

Author:
AGH CAST Team

Enum Constant Summary
RRRR_MM_DD_DASH
          yyyy-MM-dd format.
RRRR_MM_DD_DOT
          yyyy.MM.dd format e.g.
RRRR_MM_DD_SLASH
          yyyy/MM/dd format.
 
Method Summary
 String format(Date date)
          Formats given date.
static String formatDefault(Date date)
          Formats date using the default format: dd-mm-yyyy.
static String getDefaultFormat()
          Returns the default date format.
 String getFormat()
          Returns the date format.
static Date parse(String text)
          Parsed given text according to all supported formats.
static SupportedDateFormat valueOf(String name)
          Returns the enum constant of this type with the specified name.
static SupportedDateFormat[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

RRRR_MM_DD_DASH

public static final SupportedDateFormat RRRR_MM_DD_DASH
yyyy-MM-dd format. e.g. 2009-01-20 This format is used as default.


RRRR_MM_DD_SLASH

public static final SupportedDateFormat RRRR_MM_DD_SLASH
yyyy/MM/dd format. e.g. 2009/01/20


RRRR_MM_DD_DOT

public static final SupportedDateFormat RRRR_MM_DD_DOT
yyyy.MM.dd format e.g. 2009.01.20

Method Detail

values

public static SupportedDateFormat[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (SupportedDateFormat c : SupportedDateFormat.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static SupportedDateFormat valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

parse

public static Date parse(String text)
                  throws ParseException
Parsed given text according to all supported formats. The first matching format is chosen, however the formats order is not defined.

Parameters:
text - text to parse.
Returns:
parsed date object or null if text is null
Throws:
ParseException - if text does not match to any format. exception generated by the last format is thrown

formatDefault

public static String formatDefault(Date date)
Formats date using the default format: dd-mm-yyyy.

Parameters:
date - date to format
Returns:
formated date as string

format

public String format(Date date)
Formats given date.

Parameters:
date - date to format
Returns:
formated date as string or null if date is null;

getFormat

public String getFormat()
Returns the date format.

Returns:
date format

getDefaultFormat

public static String getDefaultFormat()
Returns the default date format.

Returns:
default date format


Copyright © 2007-2009 IISG AGH-UST Krakow, Poland. All Rights Reserved.