org.mmbase.datatypes
Class DateTimePattern

java.lang.Object
  extended byorg.mmbase.datatypes.DateTimePattern
All Implemented Interfaces:
Cloneable, Serializable

public class DateTimePattern
extends Object
implements Cloneable, Serializable

This is a bit like SimpleDateFormat, because it accepts the same pattern String. It can also parse the String though (see getList(java.util.Locale)), which can be used to do something else for parsing or formatting (think: format an editor entry). This utility class is of course used in the implementation of DateTimeDataType.

Since:
MMBase-1.8
Version:
$Id: DateTimePattern.java,v 1.11 2006/07/11 20:09:55 michiel Exp $
Author:
Michiel Meeuwissen
See Also:
Serialized Form

Nested Class Summary
static class DateTimePattern.Element
          A wrapper arround a field in a Calendar object.
 
Field Summary
static DateTimePattern DEFAULT
           
protected  LocalizedString pattern
           
 
Constructor Summary
DateTimePattern(String pattern)
           
 
Method Summary
 Object clone()
           
 DateFormat getDateFormat(Locale locale)
          Returns a DateFormat object associated with this object.
static DateTimePattern.Element getElement(char c, Calendar minDate, Calendar maxDate)
          Returns an DateTimePattern.Element structure assiocated with the characters of the format pattern.
 List getList(Locale locale)
          Returns the pattern 'parsed'.
 LocalizedString getPattern()
          Returns the original pattern, which can e.g.
static void main(String[] argv)
           
 void set(String pattern)
           
 void set(String pattern, Locale locale)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT

public static final DateTimePattern DEFAULT

pattern

protected LocalizedString pattern
Constructor Detail

DateTimePattern

public DateTimePattern(String pattern)
Method Detail

set

public void set(String pattern,
                Locale locale)

set

public void set(String pattern)

getDateFormat

public DateFormat getDateFormat(Locale locale)
Returns a DateFormat object associated with this object.


getPattern

public LocalizedString getPattern()
Returns the original pattern, which can e.g. be used to instantiate a SimpleDateFormat (but this is also done for you in getDateFormat(java.util.Locale).


getList

public List getList(Locale locale)
Returns the pattern 'parsed'. This means that is is a List of Strings. If the string is introduced by a quote, then it is a literal string, otherwise it is a format-string, consisting only of a number of the same letters (e.g. yyy). So by checking the first character you can decide what to do with it. If for example you are making an editor, and the first char is an quote, you may decide to do either nothing, or to write it out (without the quote). If the first character is e.g. 'y' you can make an input box for the year (you could also attribute some meaning to the length of the string then).


getElement

public static DateTimePattern.Element getElement(char c,
                                                 Calendar minDate,
                                                 Calendar maxDate)
Returns an DateTimePattern.Element structure assiocated with the characters of the format pattern. This utility function can be usefull when generating drop-downs based on the result of getList(java.util.Locale).

Parameters:
c - The pattern character. 'y', 'M', 'd', 'H', 'K', 'h', 'k', 'm', 's', 'E', 'w', 'D', 'F', 'G', 'a', or 'S'
minDate - If for example the parameter is 'y' then the 'getMin' property of the result Element will be the year of this date.
maxDate - If for example the parameter is 'y' then the 'getMax' property of the result Element will be the year of this date.

clone

public Object clone()

toString

public String toString()

main

public static void main(String[] argv)


MMBase build 1.8.1.20060716