com.miginfocom.util.dates
Class DateFormatList

java.lang.Object
  extended by com.miginfocom.util.dates.DateFormatList
All Implemented Interfaces:
java.io.Serializable

public class DateFormatList
extends java.lang.Object
implements java.io.Serializable

Similar to SimpleDateFormat but is more suited to live in a com.miginfocom.theme since it can be both Locale dependant or independant. It can also consist of more than one SimpleDateFormat separated by a vertical bar "|".

Another special formatting option for this class is that for every pattern the absolute first character my be a digit specifying the maximum number of returned characters for the resolvation of that pattern (i.e. the resulting string).

This class is not thread safe.

See Also:
Serialized Form

Field Summary
protected  java.util.Locale locale
           
protected  java.lang.String pattern
           
protected  java.util.TimeZone timeZone
           
 
Constructor Summary
DateFormatList(java.lang.String pattern)
          Constructor with null locale.
DateFormatList(java.lang.String pattern, java.util.Locale locale)
          Constructor with null locale.
DateFormatList(java.lang.String pattern, java.util.Locale locale, java.util.TimeZone timeZone)
          Constructor with null locale.
 
Method Summary
 boolean equals(java.lang.Object o)
           
 java.lang.String[] format(java.util.Date dateTime)
          Returns the strings for the contained date formats.
 java.lang.String[] format(java.util.Locale locale, java.util.Date dateTime)
          Returns the strings for the contained date formats
 java.lang.String[] format(java.util.Locale locale, java.util.TimeZone timeZone, java.util.Date dateTime)
          Returns the strings for the contained date formats
 java.lang.String formatFirst(java.util.Date dateTime)
          Returns the first string for the contained date formats.
 java.lang.String formatFirst(java.util.Locale locale, java.util.Date dateTime)
          Returns the first string for the contained date formats.
 java.lang.String formatFirst(java.util.Locale locale, java.util.TimeZone timeZone, java.util.Date dateTime)
          Returns the first string for the contained date formats.
 int getFormatCount()
          Returns the number of date formats the pattern indicates.
 java.util.Locale getLocale()
          Returns the Locale
 java.lang.String getPattern()
          Returns the pattern string
 java.util.TimeZone getTimeZone()
          Returns the time zone.
 java.util.Date parse(java.lang.String string, java.util.Date baseDate)
          Parses the string, with an optional base date.
 java.util.Date parse(java.lang.String string, java.util.Date baseDate, boolean lenient)
          Parses the string, with an optional base date.
 java.text.SimpleDateFormat toSimpleDateFormat(java.util.Locale locale)
          Returns a SimpleDateFormat.
 java.text.SimpleDateFormat toSimpleDateFormat(java.util.Locale locale, java.util.TimeZone timeZone)
          Returns a SimpleDateFormat.
 java.text.SimpleDateFormat[] toSimpleDateFormats(java.util.Locale locale)
          Returns a number of SimpleDateFormats.
 java.text.SimpleDateFormat[] toSimpleDateFormats(java.util.Locale locale, java.util.TimeZone timeZone)
          Returns a number of SimpleDateFormats.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pattern

protected final transient java.lang.String pattern

locale

protected final transient java.util.Locale locale

timeZone

protected final transient java.util.TimeZone timeZone
Constructor Detail

DateFormatList

public DateFormatList(java.lang.String pattern)
Constructor with null locale.

Parameters:
pattern - The pattern, same as for SimpleDateFormat. Can also be used to specify multiple patterns. These are divided with "|" which means that DateFormatList doesn't support normal patterns with character.

Another special formatting option for this class is that for every pattern the absolute first character my be a digit specifying the maximum number of returned characters for the resolvation of that pattern (i.e. the resulting string).

See Also:
toSimpleDateFormat(java.util.Locale)

DateFormatList

public DateFormatList(java.lang.String pattern,
                      java.util.Locale locale)
Constructor with null locale.

Parameters:
pattern - The pattern, same as for SimpleDateFormat. Can also be used to specify multiple patterns. These are divided with "|" which means that DateFormatList doesn't support normal patterns with character.

Another special formatting option for this class is that for every pattern the absolute first character my be a digit specifying the maximum number of returned characters for the resolvation of that pattern (i.e. the resulting string).

locale - The locale to always use. If null the default locale will be used.
See Also:
createSimpleDateFormats(java.util.Locale, java.util.TimeZone), toSimpleDateFormat(java.util.Locale)

DateFormatList

public DateFormatList(java.lang.String pattern,
                      java.util.Locale locale,
                      java.util.TimeZone timeZone)
Constructor with null locale.

Parameters:
pattern - The pattern, same as for SimpleDateFormat. Can also be used to specify multiple patterns. These are divided with "|" which means that DateFormatList doesn't support normal patterns with character.

Another special formatting option for this class is that for every pattern the absolute first character my be a digit specifying the maximum number of returned characters for the resolvation of that pattern (i.e. the resulting string).

locale - The locale to always use. If null the default locale will be used.
timeZone - The time zone. If null the default time zone will be used.
See Also:
createSimpleDateFormats(java.util.Locale, java.util.TimeZone), toSimpleDateFormat(java.util.Locale)
Method Detail

toSimpleDateFormat

public java.text.SimpleDateFormat toSimpleDateFormat(java.util.Locale locale)
Returns a SimpleDateFormat. If the pattern indicates more than one format, the first one is returned.

Parameters:
locale - The locale to use. If null the local stored will be used. If that is null the default one will be used.
Returns:
A newly created SimpleDateFormat

toSimpleDateFormat

public java.text.SimpleDateFormat toSimpleDateFormat(java.util.Locale locale,
                                                     java.util.TimeZone timeZone)
Returns a SimpleDateFormat. If the pattern indicates more than one format, the first one is returned.

Parameters:
locale - The locale to use. If null the local stored will be used. If that is null the default one will be used.
timeZone - The time zone to use. If null the local stored will be used. If that is null the default one will be used.
Returns:
A newly created SimpleDateFormat

toSimpleDateFormats

public java.text.SimpleDateFormat[] toSimpleDateFormats(java.util.Locale locale)
Returns a number of SimpleDateFormats. (At least one). Note that the returned SimpleDateFormats does not impose the maxChars property since it can't contain that information in the pattern. Use format(java.util.Date) instead.

The simple date formats are cached and new ones will only be created if the locale is different from the cached one.

Parameters:
locale - The locale to use. If null the local stored will be used. If that is null the default one will be used.
Returns:
The SimpleDateFormats. The array is live so it must not be changed.

toSimpleDateFormats

public java.text.SimpleDateFormat[] toSimpleDateFormats(java.util.Locale locale,
                                                        java.util.TimeZone timeZone)
Returns a number of SimpleDateFormats. (At least one). Note that the returned SimpleDateFormats does not impose the maxChars property since it can't contain that information in the pattern. Use format(java.util.Date) instead.

The simple date formats are cached and new ones will only be created if the locale is different from the cached one.

Parameters:
locale - The locale to use. If null the local stored will be used. If that is null the default one will be used.
timeZone - The time zone to use. If null the local stored will be used. If that is null the default one will be used.
Returns:
The SimpleDateFormats. The array is live so it must not be changed.

getFormatCount

public int getFormatCount()
Returns the number of date formats the pattern indicates. (normally the number of "|" + 1)

Returns:
The number of date formats the pattern indicates.

format

public java.lang.String[] format(java.util.Date dateTime)
Returns the strings for the contained date formats.

If the local stored locale is not null it will be used. If it is null the default one will be used.

Parameters:
dateTime - The date/time to format
Returns:
A newly created arrays of strings with the dates formatted as text. Not null or null elements. At least of length 1.

format

public java.lang.String[] format(java.util.Locale locale,
                                 java.util.Date dateTime)
Returns the strings for the contained date formats

Parameters:
locale - The locale to use. If null the local stored will be used. If that is null the default one will be used.
dateTime - The date/time to format
Returns:
A newly created arrays of strings with the dates formatted as text. Not null or null elements. At least of length 1.

format

public java.lang.String[] format(java.util.Locale locale,
                                 java.util.TimeZone timeZone,
                                 java.util.Date dateTime)
Returns the strings for the contained date formats

Parameters:
locale - The locale to use. If null the local stored will be used. If that is null the default one will be used.
timeZone - The time zone to use. If null the local stored will be used. If that is null the default one will be used.
dateTime - The date/time to format
Returns:
A newly created arrays of strings with the dates formatted as text. Not null or null elements. At least of length 1.

formatFirst

public java.lang.String formatFirst(java.util.Date dateTime)
Returns the first string for the contained date formats.

If the local stored locale is not null it will be used. If it is null the default one will be used.

Parameters:
dateTime - The date/time to format.
Returns:
The first string for the contained date formats. Not null.

formatFirst

public java.lang.String formatFirst(java.util.Locale locale,
                                    java.util.Date dateTime)
Returns the first string for the contained date formats.

Parameters:
locale - The locale to use. If null the local stored will be used. If that is null the default one will be used.
dateTime - The date/time to format
Returns:
The first string for the contained date formats. Not null.

formatFirst

public java.lang.String formatFirst(java.util.Locale locale,
                                    java.util.TimeZone timeZone,
                                    java.util.Date dateTime)
Returns the first string for the contained date formats.

Parameters:
locale - The locale to use. If null the local stored will be used. If that is null the default one will be used.
timeZone - The time zone to use. If null the local stored will be used. If that is null the default one will be used.
dateTime - The date/time to format
Returns:
The first string for the contained date formats. Not null.

parse

public java.util.Date parse(java.lang.String string,
                            java.util.Date baseDate)
                     throws java.text.ParseException
Parses the string, with an optional base date. Calendar fields not in the string (for instance year) will be extracted from baseDate insted. This can not be done with a normal SimpleDateFormat.

Parsing will be lenient.

Parameters:
string - The string to parse
baseDate - Optional base date if string is missing information, such as the year.
Returns:
The parsed date. Never null.
Throws:
java.text.ParseException

parse

public java.util.Date parse(java.lang.String string,
                            java.util.Date baseDate,
                            boolean lenient)
                     throws java.text.ParseException
Parses the string, with an optional base date. Calendar fields not in the string (for instance year) will be extracted from baseDate insted. This can not be done with a normal SimpleDateFormat.

Parameters:
string - The string to parse
baseDate - Optional base date if string is missing information, such as the year.
lenient - If the parsing should be leninet.
Returns:
The parsed date. Never null.
Throws:
java.text.ParseException
See Also:
DateFormat.setLenient(boolean)

getPattern

public java.lang.String getPattern()
Returns the pattern string

Returns:
The pattern string

getLocale

public java.util.Locale getLocale()
Returns the Locale

Returns:
The Locale, can be null.

getTimeZone

public java.util.TimeZone getTimeZone()
Returns the time zone.

Returns:
The time zone, can be null.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.