org.norther.tammi.core.converter
Interface DateConverter

All Superinterfaces:
ObjectConverter<Object>
All Known Implementing Classes:
DefaultDateConverter

public interface DateConverter
extends ObjectConverter<Object>

A converter for instances representing dates and time zones. Source classes to support: java.util.Date, longs as a primitive type or as java.lang.Long and org.norther.tammi.acorn.lang.LongDate, and strings as org.norther.tammi.acorn.lang.StringDate, and time zones as java.util.TimeZone.

The styles can be given as a pattern to format or parse a date, time, or a datetime. The default is a datetime. If you want to have dates without time information or vice versa or want to have a different style for the date and time part, you'll need to add a qualifier in front of the style and put the style(s) in parantheses.

After the styles, you can also add a time zone id as defined in java.util.TimeZone.

Examples:

The pattern can also be a format understood by the java.text.SimpleDateFormat.

A special style "ISO-8601" indicates a date with the format yyyy-MM-dd and a time with the format HH:mm:ss. E.g. the pattern "datetime(ISO-8601)" is equal to the pattern "yyyy-MM-dd HH:mm:ss".

Version:
$Id: DateConverter.java,v 1.23 2010-05-19 09:43:19 cvsimp Exp $
Author:
Marketta Priha

Field Summary
static String DEFAULT_STYLE
          Default style.
static String FULL_STYLE
          Full style.
static String LONG_STYLE
          Long style.
static String MEDIUM_STYLE
          Medium style.
static String SHORT_STYLE
          Short style.
 
Method Summary
 Set<String> classNameSet()
          Returns a read-only set of class names of defined patterns.
 void clearClassSpecificPatterns()
          Clears all class specific patterns.
 void clearLocalPatternChars()
          Clears all locale specific pattern chars.
 String getClassSpecificPattern(String className)
          Gets the class specific default date pattern.
 DateFormat getDateFormat(String className, String pattern, Locale... locale)
          Gets a date format for the specified class, pattern and locale.
 String getDefaultPattern()
          Gets the default date pattern.
 String getExcelPattern(String className, String pattern, Locale... locale)
          Gets an Excel format pattern for the specified class, pattern and locale.
 String getLocalPatternChars(Locale locale)
          Gets the locale specific pattern chars.
 String getTimeZoneId()
          Gets the default time zone to apply.
 Set<Locale> patternLocaleSet()
          Returns a read-only set of locales with defined pattern chars.
 void removeClassSpecificPattern(String className)
          Removes the class specific default date pattern.
 void removeLocalPatternChars(Locale locale)
          Removes the locale specific pattern chars.
 void setClassSpecificPattern(String className, String pattern)
          Sets the class specific default date pattern.
 void setDefaultPattern(String pattern)
          Sets the default date pattern.
 void setLocalPatternChars(Locale locale, String chars)
          Sets the locale specific pattern chars.
 void setTimeZoneId(String id)
          Sets the default time zone to apply.
 List<String> timeZoneIds()
          Returns a list of supported time zone ids.
 Date toDate(long msecs)
          Converts milliseconds to date.
 long toTime(Date date)
          Converts a date to milliseconds.
 
Methods inherited from interface org.norther.tammi.core.converter.ObjectConverter
getFormatPattern, getInstance, getInstance, getInstance, getLocalizedPattern, getResourceFinderName, setResourceFinderName, toString, toString, toString, toStrings, toStrings, toStrings
 

Field Detail

DEFAULT_STYLE

static final String DEFAULT_STYLE
Default style.

See Also:
Constant Field Values

SHORT_STYLE

static final String SHORT_STYLE
Short style.

See Also:
Constant Field Values

MEDIUM_STYLE

static final String MEDIUM_STYLE
Medium style.

See Also:
Constant Field Values

LONG_STYLE

static final String LONG_STYLE
Long style.

See Also:
Constant Field Values

FULL_STYLE

static final String FULL_STYLE
Full style.

See Also:
Constant Field Values
Method Detail

getDefaultPattern

String getDefaultPattern()
Gets the default date pattern.

Returns:
the default date pattern.

setDefaultPattern

void setDefaultPattern(String pattern)
Sets the default date pattern.

Parameters:
pattern - the default date pattern.

getClassSpecificPattern

String getClassSpecificPattern(String className)
Gets the class specific default date pattern.

Parameters:
className - the class name of the pattern.
Returns:
the class specific default date pattern.

setClassSpecificPattern

void setClassSpecificPattern(String className,
                             String pattern)
Sets the class specific default date pattern.

Parameters:
className - the class name of the pattern.
pattern - the class specific default date pattern.

removeClassSpecificPattern

void removeClassSpecificPattern(String className)
Removes the class specific default date pattern.

Parameters:
className - the class name of the pattern.

clearClassSpecificPatterns

void clearClassSpecificPatterns()
Clears all class specific patterns.


classNameSet

Set<String> classNameSet()
Returns a read-only set of class names of defined patterns.

Returns:
a set of class names.

getLocalPatternChars

String getLocalPatternChars(Locale locale)
Gets the locale specific pattern chars.

Parameters:
locale - the locale.
Returns:
the pattern chars.

setLocalPatternChars

void setLocalPatternChars(Locale locale,
                          String chars)
Sets the locale specific pattern chars.

Parameters:
locale - the locale.
chars - the pattern chars.

removeLocalPatternChars

void removeLocalPatternChars(Locale locale)
Removes the locale specific pattern chars.

Parameters:
locale - the locale.

clearLocalPatternChars

void clearLocalPatternChars()
Clears all locale specific pattern chars.


patternLocaleSet

Set<Locale> patternLocaleSet()
Returns a read-only set of locales with defined pattern chars.

Returns:
a set of locales.

getTimeZoneId

String getTimeZoneId()
Gets the default time zone to apply.

Returns:
the time zone id.

setTimeZoneId

void setTimeZoneId(String id)
Sets the default time zone to apply.

Note that this method changes the default time zone of the running JVM to the specified value and thus may interfere with other date functionality.

Parameters:
id - the time zone id.

timeZoneIds

List<String> timeZoneIds()
Returns a list of supported time zone ids.

Returns:
a read-only list of time zone ids.

getDateFormat

DateFormat getDateFormat(String className,
                         String pattern,
                         Locale... locale)
Gets a date format for the specified class, pattern and locale.

Parameters:
className - the name of the class to format.
pattern - the conversion pattern.
locale - the locale.
Returns:
the requested date format.
See Also:
DateFormat

getExcelPattern

String getExcelPattern(String className,
                       String pattern,
                       Locale... locale)
Gets an Excel format pattern for the specified class, pattern and locale.

Parameters:
className - the name of the class to format.
pattern - the conversion pattern.
locale - the locale.
Returns:
the requested date format.

toTime

long toTime(Date date)
Converts a date to milliseconds.

Parameters:
date - the date.
Returns:
the date in millis.

toDate

Date toDate(long msecs)
Converts milliseconds to date.

Parameters:
msecs - the millis.
Returns:
the millis as date.


Copyright © 2004 The Norther Organization. All rights reserved.