com.logikdev.jsftools
Class StaticDateTool

java.lang.Object
  extended by com.logikdev.jsftools.StaticDateTool
Direct Known Subclasses:
StaticComparisonDateTool

public class StaticDateTool
extends java.lang.Object

Tool for working with Date and Calendar in JSF. It is useful for accessing and formatting the "current" date as well as for formatting arbitrary Date and Calendar objects. Also the tool can be used to retrieve DateFormat instances or make conversions to and from various date types.

Since:
0.3
Author:
Stéphane Moreau
See Also:
org.apache.velocity.tools.generic.DateTool

Constructor Summary
StaticDateTool()
           
 
Method Summary
static java.lang.String format(java.lang.Object obj)
          Converts the specified object to a date and formats it according to the pattern or style returned by FormatConfig.getFormat().
static java.lang.String format(java.lang.String format, java.lang.Object obj)
          Converts the specified object to a date and returns a formatted string representing that date in the locale returned by LocaleConfig.getLocale().
static java.lang.String format(java.lang.String format, java.lang.Object obj, java.util.Locale locale)
          Converts the specified object to a date and returns a formatted string representing that date in the specified Locale.
static java.lang.String format(java.lang.String format, java.lang.Object obj, java.util.Locale locale, java.util.TimeZone timezone)
          Returns a formatted string representing the specified date, Locale, and TimeZone.
static java.lang.String format(java.lang.String dateStyle, java.lang.String timeStyle, java.lang.Object obj)
          Returns the specified date as a string formatted according to the specified date and/or time styles.
static java.lang.String format(java.lang.String dateStyle, java.lang.String timeStyle, java.lang.Object obj, java.util.Locale locale)
          Returns the specified date as a string formatted according to the specified Locale and date and/or time styles.
static java.lang.String format(java.lang.String dateStyle, java.lang.String timeStyle, java.lang.Object obj, java.util.Locale locale, java.util.TimeZone timezone)
          Returns the specified date as a string formatted according to the specified Locale and date and/or time styles.
static java.lang.String get(java.lang.String format)
          Returns a formatted string representing the date returned by getDate().
static java.lang.String get(java.lang.String dateStyle, java.lang.String timeStyle)
          Returns a formatted string representing the date and/or time given by getDate() in standard, localized patterns.
static java.util.Calendar getCalendar()
          Returns a Calendar instance created using the timezone and locale returned by getTimeZone() and getLocale().
static java.util.Date getDate()
          Returns a Date derived from the result of getCalendar().
static java.text.DateFormat getDateFormat(java.lang.String format, java.util.Locale locale, java.util.TimeZone timezone)
          Returns a DateFormat instance for the specified format, Locale, and TimeZone.
static java.text.DateFormat getDateFormat(java.lang.String dateStyle, java.lang.String timeStyle, java.util.Locale locale, java.util.TimeZone timezone)
          Returns a DateFormat instance for the specified date style, time style, Locale, and TimeZone.
static java.lang.Integer getDay()
          Returns the day (of the month) value of the date returned by getCalendar().
static java.lang.Integer getDay(java.lang.Object date)
          Returns the day (of the month) value for the specified date.
static java.lang.Integer getMonth()
          Returns the month value of the date returned by getCalendar().
static java.lang.Integer getMonth(java.lang.Object date)
          Returns the month value of the specified date.
static java.util.Calendar getSystemCalendar()
          Returns the system's current time as a Calendar.
static java.util.Date getSystemDate()
          Returns the system's current time as a Date.
static long getSystemTime()
          Returns the system's current time as the number of milliseconds elapsed since January 1, 1970, 00:00:00 GMT.
static java.util.TimeZone getTimeZone()
          Returns the configured TimeZone.
static java.lang.Integer getValue(int field, java.lang.Object date)
          Returns the specified value of the specified date, or null if the field or date is invalid.
static java.lang.Integer getValue(java.lang.Object field)
          Return the specified value of the date returned by getCalendar() or null if the field is invalid.
static java.lang.Integer getValue(java.lang.Object field, java.lang.Object date)
          Returns the specified value of the specified date, or null if the field or date is invalid.
static java.lang.Integer getYear()
          Returns the year value of the date returned by getCalendar().
static java.lang.Integer getYear(java.lang.Object date)
          Returns the year value of the specified date.
static java.util.Calendar toCalendar(java.lang.Object obj)
          Converts an object to an instance of Calendar using the locale returned by LocaleConfig.getLocale() if necessary.
static java.util.Calendar toCalendar(java.lang.Object obj, java.util.Locale locale)
          Converts an object to an instance of Calendar using the locale returned by LocaleConfig.getLocale() if necessary.
static java.util.Date toDate(java.lang.Object obj)
          Converts an object to an instance of Date.
static java.util.Date toDate(java.lang.String format, java.lang.Object obj)
          Converts an object to an instance of Date using the specified format.
static java.util.Date toDate(java.lang.String format, java.lang.Object obj, java.util.Locale locale)
          Converts an object to an instance of Date using the specified format and Locale.
static java.util.Date toDate(java.lang.String format, java.lang.Object obj, java.util.Locale locale, java.util.TimeZone timezone)
          Converts an object to an instance of Date using the specified format, Locale, and TimeZone.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StaticDateTool

public StaticDateTool()
Method Detail

format

public static final java.lang.String format(java.lang.Object obj)
Converts the specified object to a date and formats it according to the pattern or style returned by FormatConfig.getFormat().

Parameters:
obj - The date object to be formatted
Returns:
The specified date formatted as a string
See Also:
org.apache.velocity.tools.generic.DateTool#format(java.lang.Object)

format

public static final java.lang.String format(java.lang.String format,
                                            java.lang.Object obj)
Converts the specified object to a date and returns a formatted string representing that date in the locale returned by LocaleConfig.getLocale().

Parameters:
format - The formatting instructions
obj - The date object to be formatted
Returns:
A formatted string for this locale representing the specified date or null if the parameters are invalid
See Also:
org.apache.velocity.tools.generic.DateTool#format(java.lang.String, java.lang.Object)

format

public static final java.lang.String format(java.lang.String format,
                                            java.lang.Object obj,
                                            java.util.Locale locale)
Converts the specified object to a date and returns a formatted string representing that date in the specified Locale.

Parameters:
format - The formatting instructions
obj - The date object to be formatted
locale - The locale to be used when formatting
Returns:
The given date as a formatted string
See Also:
org.apache.velocity.tools.generic.DateTool#format(java.lang.String, java.lang.Object, java.util.Locale)

format

public static final java.lang.String format(java.lang.String format,
                                            java.lang.Object obj,
                                            java.util.Locale locale,
                                            java.util.TimeZone timezone)
Returns a formatted string representing the specified date, Locale, and TimeZone.

Parameters:
format - The formatting instructions
obj - The date object to be formatted
locale - The Locale to be used when formatting
timezone - The TimeZone to be used when formatting
Returns:
A formatted string representing the specified date or null if the parameters are invalid
See Also:
org.apache.velocity.tools.generic.DateTool#format(java.lang.String, java.lang.Object, java.util.Locale, java.util.TimeZone)

format

public static final java.lang.String format(java.lang.String dateStyle,
                                            java.lang.String timeStyle,
                                            java.lang.Object obj)
Returns the specified date as a string formatted according to the specified date and/or time styles.

Parameters:
dateStyle - The style pattern for the date
timeStyle - The style pattern for the time
obj - The date to be formatted
Returns:
A formatted representation of the given date
See Also:
org.apache.velocity.tools.generic.DateTool#format(java.lang.String, java.lang.String, java.lang.Object)

format

public static final java.lang.String format(java.lang.String dateStyle,
                                            java.lang.String timeStyle,
                                            java.lang.Object obj,
                                            java.util.Locale locale)
Returns the specified date as a string formatted according to the specified Locale and date and/or time styles.

Parameters:
dateStyle - The style pattern for the date
timeStyle - The style pattern for the time
obj - The date to be formatted
locale - The Locale to be used for formatting the date
Returns:
A formatted representation of the given date
See Also:
org.apache.velocity.tools.generic.DateTool#format(java.lang.String, java.lang.String, java.lang.Object, java.util.Locale)

format

public static final java.lang.String format(java.lang.String dateStyle,
                                            java.lang.String timeStyle,
                                            java.lang.Object obj,
                                            java.util.Locale locale,
                                            java.util.TimeZone timezone)
Returns the specified date as a string formatted according to the specified Locale and date and/or time styles.

Parameters:
dateStyle - The style pattern for the date
timeStyle - The style pattern for the time
obj - The date to be formatted
locale - The Locale to be used for formatting the date
timezone - The TimeZone the date should be formatted for
Returns:
A formatted representation of the given date
See Also:
org.apache.velocity.tools.generic.DateTool#format(java.lang.String, java.lang.String, java.lang.Object, java.util.Locale, java.util.TimeZone)

get

public static final java.lang.String get(java.lang.String format)
Returns a formatted string representing the date returned by getDate().

Parameters:
format - The formatting instructions
Returns:
A formatted representation of the date returned by getDate()
See Also:
org.apache.velocity.tools.generic.DateTool#get(java.lang.String)

get

public static final java.lang.String get(java.lang.String dateStyle,
                                         java.lang.String timeStyle)
Returns a formatted string representing the date and/or time given by getDate() in standard, localized patterns.

Parameters:
dateStyle - The style pattern for the date
timeStyle - The style pattern for the time
Returns:
A formatted representation of the date returned by getDate()
See Also:
org.apache.velocity.tools.generic.DateTool#get(java.lang.String, java.lang.String)

getCalendar

public static final java.util.Calendar getCalendar()
Returns a Calendar instance created using the timezone and locale returned by getTimeZone() and getLocale().

Returns:
A Calendar instance created using the results of getTimeZone() and LocaleConfig.getLocale()
See Also:
org.apache.velocity.tools.generic.DateTool#getCalendar()

getDate

public static final java.util.Date getDate()
Returns a Date derived from the result of getCalendar().

Returns:
A Date derived from the result of getCalendar()
See Also:
org.apache.velocity.tools.generic.DateTool#getDate()

getDateFormat

public static final java.text.DateFormat getDateFormat(java.lang.String format,
                                                       java.util.Locale locale,
                                                       java.util.TimeZone timezone)
Returns a DateFormat instance for the specified format, Locale, and TimeZone.

Parameters:
format - The custom or standard formatting pattern to be used
locale - The Locale to be used
timezone - The TimeZone to be used
Returns:
An instance of DateFormat
See Also:
org.apache.velocity.tools.generic.DateTool#getDateFormat(java.lang.String, java.util.Locale, java.util.TimeZone)

getDateFormat

public static final java.text.DateFormat getDateFormat(java.lang.String dateStyle,
                                                       java.lang.String timeStyle,
                                                       java.util.Locale locale,
                                                       java.util.TimeZone timezone)
Returns a DateFormat instance for the specified date style, time style, Locale, and TimeZone.

Parameters:
dateStyle - The date style
timeStyle - The time style
locale - The Locale to be used
timezone - The TimeZone to be used
Returns:
An instance of DateFormat
See Also:
org.apache.velocity.tools.generic.DateTool#getDateFormat(java.lang.String, java.lang.String, java.util.Locale, java.util.TimeZone)

getDay

public static final java.lang.Integer getDay()
Returns the day (of the month) value of the date returned by getCalendar().

Returns:
The day (of the month) value
See Also:
org.apache.velocity.tools.generic.DateTool#getDay()

getDay

public static final java.lang.Integer getDay(java.lang.Object date)
Returns the day (of the month) value for the specified date.

Parameters:
date - The specified date
Returns:
The day (of the month) value
See Also:
org.apache.velocity.tools.generic.DateTool#getDay(java.lang.Object)

getMonth

public static final java.lang.Integer getMonth()
Returns the month value of the date returned by getCalendar().

Returns:
The month value
See Also:
org.apache.velocity.tools.generic.DateTool#getMonth()

getMonth

public static final java.lang.Integer getMonth(java.lang.Object date)
Returns the month value of the specified date.

Parameters:
date - The specified date
Returns:
The month value
See Also:
org.apache.velocity.tools.generic.DateTool#getMonth(java.lang.Object)

getSystemCalendar

public static final java.util.Calendar getSystemCalendar()
Returns the system's current time as a Calendar.

Returns:
The system's current time as a Calendar
See Also:
org.apache.velocity.tools.generic.DateTool#getSystemCalendar()

getSystemDate

public static final java.util.Date getSystemDate()
Returns the system's current time as a Date.

Returns:
The system's current time as a Date
See Also:
org.apache.velocity.tools.generic.DateTool#getSystemDate()

getSystemTime

public static final long getSystemTime()
Returns the system's current time as the number of milliseconds elapsed since January 1, 1970, 00:00:00 GMT.

Returns:
The system's current time as the number of milliseconds elapsed since January 1, 1970, 00:00:00 GMT
See Also:
org.apache.velocity.tools.generic.DateTool#getSystemTime()

getTimeZone

public static final java.util.TimeZone getTimeZone()
Returns the configured TimeZone.

Returns:
The configured TimeZone
See Also:
org.apache.velocity.tools.generic.DateTool#getTimeZone()

getValue

public static final java.lang.Integer getValue(int field,
                                               java.lang.Object date)
Returns the specified value of the specified date, or null if the field or date is invalid.

Parameters:
field - The int for the desired field (e.g. Calendar.MONTH)
date - The date/calendar from which the field value will be taken
Returns:
The specified value of the specified date, or null if the field or date is invalid
See Also:
org.apache.velocity.tools.generic.DateTool#getValue(int, java.lang.Object)

getValue

public static final java.lang.Integer getValue(java.lang.Object field)
Return the specified value of the date returned by getCalendar() or null if the field is invalid.

Parameters:
field - The int for the desired field (e.g. Calendar.MONTH)
Returns:
The specified value of the date returned by getCalendar() or null if the field is invalid
See Also:
org.apache.velocity.tools.generic.DateTool#getValue(java.lang.Object)

getValue

public static final java.lang.Integer getValue(java.lang.Object field,
                                               java.lang.Object date)
Returns the specified value of the specified date, or null if the field or date is invalid.

Parameters:
field - The corresponding Integer value or String name of the desired value
date - The date/calendar from which the field value will be taken
Returns:
The specified value of the specified date, or null if the field or date is invalid
See Also:
org.apache.velocity.tools.generic.DateTool#getValue(java.lang.Object, java.lang.Object)

getYear

public static final java.lang.Integer getYear()
Returns the year value of the date returned by getCalendar().

Returns:
The year value
See Also:
org.apache.velocity.tools.generic.DateTool#getYear()

getYear

public static final java.lang.Integer getYear(java.lang.Object date)
Returns the year value of the specified date.

Parameters:
date - The specified date
Returns:
The year value
See Also:
org.apache.velocity.tools.generic.DateTool#getYear(java.lang.Object)

toCalendar

public static final java.util.Calendar toCalendar(java.lang.Object obj)
Converts an object to an instance of Calendar using the locale returned by LocaleConfig.getLocale() if necessary.

Parameters:
obj - The date to convert
Returns:
The converted date
See Also:
org.apache.velocity.tools.generic.DateTool#toCalendar(java.lang.Object)

toCalendar

public static final java.util.Calendar toCalendar(java.lang.Object obj,
                                                  java.util.Locale locale)
Converts an object to an instance of Calendar using the locale returned by LocaleConfig.getLocale() if necessary.

Parameters:
obj - The date to convert
locale - The locale used
Returns:
The converted date
See Also:
org.apache.velocity.tools.generic.DateTool#toCalendar(java.lang.Object, java.util.Locale)

toDate

public static final java.util.Date toDate(java.lang.Object obj)
Converts an object to an instance of Date.

Parameters:
obj - The date to convert
Returns:
The object as a Date or null if no conversion is possible
See Also:
org.apache.velocity.tools.generic.DateTool#toDate(java.lang.Object)

toDate

public static final java.util.Date toDate(java.lang.String format,
                                          java.lang.Object obj)
Converts an object to an instance of Date using the specified format.

Parameters:
format - The format the date is in
obj - The date to convert
Returns:
The object as a Date or null if no conversion is possible
See Also:
org.apache.velocity.tools.generic.DateTool#toDate(java.lang.String, java.lang.Object)

toDate

public static final java.util.Date toDate(java.lang.String format,
                                          java.lang.Object obj,
                                          java.util.Locale locale)
Converts an object to an instance of Date using the specified format and Locale.

Parameters:
format - The format the date is in
obj - The date to convert
locale - The Locale
Returns:
The object as a Date or null if no conversion is possible
See Also:
org.apache.velocity.tools.generic.DateTool#toDate(java.lang.String, java.lang.Object, java.util.Locale)

toDate

public static final java.util.Date toDate(java.lang.String format,
                                          java.lang.Object obj,
                                          java.util.Locale locale,
                                          java.util.TimeZone timezone)
Converts an object to an instance of Date using the specified format, Locale, and TimeZone.

Parameters:
format - The format the date is in
obj - The date to convert
locale - The Locale
timezone - The TimeZone
Returns:
the object as a Date or null if no conversion is possible
See Also:
org.apache.velocity.tools.generic.DateTool#toDate(java.lang.String, java.lang.Object, java.util.Locale, java.util.TimeZone)


Copyright © 2009-2010 Logik Development. All Rights Reserved.