net.sf.seaf.util
Class TemporalConverterUtil

java.lang.Object
  extended by net.sf.seaf.util.TemporalConverterUtil

public class TemporalConverterUtil
extends Object

Utility methods for converting temporal types.


Constructor Summary
TemporalConverterUtil()
           
 
Method Summary
static void backwardValidationOfStringValue(String originalValue, Calendar parsedValue, String format)
          Throw IllegalArgumentException when the parsed Calendar value does not match the original String value, from which it has been parsed.
static Calendar convert(Object o, String format)
          Convert an object to a Calendar.
static String formatDate(Calendar value, String format)
          Format a Calendar value as a String using the given format.
static Calendar parseDate(String text, String format)
          Parse a Calendar from String value using a Java date format pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TemporalConverterUtil

public TemporalConverterUtil()
Method Detail

convert

public static Calendar convert(Object o,
                               String format)
                        throws IllegalArgumentException
Convert an object to a Calendar.

Passes null unchanged. Passes Calendar unchanged. Converts Date. Otherwise, parses the passed object as String using the format supplied.

Parameters:
o - The object to be converted
format - The Java date format pattern, see DateFormat
Returns:
Calendar The object converted to Calendar
Throws:
IllegalArgumentException - Thrown when the supplied object is not a valid temporal value given the format specified

parseDate

public static Calendar parseDate(String text,
                                 String format)
                          throws IllegalArgumentException
Parse a Calendar from String value using a Java date format pattern.

Parameters:
text - The String containing temporal value representation
format - The Java date format pattern, see DateFormat
Returns:
Calendar The text converted to Calendar
Throws:
IllegalArgumentException - Thrown when the supplied text is not a valid temporal value given the format specified

backwardValidationOfStringValue

public static void backwardValidationOfStringValue(String originalValue,
                                                   Calendar parsedValue,
                                                   String format)
                                            throws IllegalArgumentException
Throw IllegalArgumentException when the parsed Calendar value does not match the original String value, from which it has been parsed.

Parameters:
originalValue - The original String value
parsedValue - The parsed Calendar value
format - The format used for parsing
Throws:
IllegalArgumentException - Thrown when the parsed value does not match the original value

formatDate

public static String formatDate(Calendar value,
                                String format)
Format a Calendar value as a String using the given format.

Parameters:
value - Calendar value
format - Format to use
Returns:
String Formatted value


Copyright © 2008-2012 SEAF. All Rights Reserved.