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

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

public enum SupportedTimeFormat
extends Enum<SupportedTimeFormat>

Defines time formats and provides basic methods for parsing and formating times.

Supported time formats:

For more details about defining time formats see SimpleDateFormat

Author:
AGH CAST Team

Enum Constant Summary
HH_MM_A_COLON
          hh:mm a format, e.g.
HH_MM_COLON
          HH:mm format, e.g.
HH_MM_SS_A_COLON
          hh:mm:ss a format, e.g.
HH_MM_SS_COLON
          HH:mm:ss format, e.g.
 
Method Summary
 String format(Date time)
          Formats given time.
static String formatDefault(Date time)
          Formats time using the default format: HH:mm:ss.
static String getDefaultFormat()
          Returns the default time format.
 String getFormat()
          Returns the time format.
static Date parse(String text)
          Parsed given text according to all supported formats.
static SupportedTimeFormat valueOf(String name)
          Returns the enum constant of this type with the specified name.
static SupportedTimeFormat[] 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

HH_MM_SS_COLON

public static final SupportedTimeFormat HH_MM_SS_COLON
HH:mm:ss format, e.g. 15:05:23 This format is used as default.


HH_MM_COLON

public static final SupportedTimeFormat HH_MM_COLON
HH:mm format, e.g. 15:05


HH_MM_SS_A_COLON

public static final SupportedTimeFormat HH_MM_SS_A_COLON
hh:mm:ss a format, e.g. 03:05:23 PM


HH_MM_A_COLON

public static final SupportedTimeFormat HH_MM_A_COLON
hh:mm a format, e.g. 03:05 PM

Method Detail

values

public static SupportedTimeFormat[] 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 (SupportedTimeFormat c : SupportedTimeFormat.values())
    System.out.println(c);

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

valueOf

public static SupportedTimeFormat 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 time)
Formats time using the default format: HH:mm:ss.

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

format

public String format(Date time)
Formats given time.

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

getFormat

public String getFormat()
Returns the time format.

Returns:
time format

getDefaultFormat

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

Returns:
default time format


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