org.omnifaces.el.functions
Class Dates

java.lang.Object
  extended by org.omnifaces.el.functions.Dates

public final class Dates
extends java.lang.Object

Collection of EL functions for date and time.

Author:
Bauke Scholtz

Method Summary
static java.util.Date addDays(java.util.Date date, int days)
          Returns a new date instance which is a sum of the given date and the given amount of days.
static java.util.Date addHours(java.util.Date date, int hours)
          Returns a new date instance which is a sum of the given date and the given amount of hours.
static java.util.Date addMinutes(java.util.Date date, int minutes)
          Returns a new date instance which is a sum of the given date and the given amount of minutes.
static java.util.Date addMonths(java.util.Date date, int months)
          Returns a new date instance which is a sum of the given date and the given amount of months.
static java.util.Date addSeconds(java.util.Date date, int seconds)
          Returns a new date instance which is a sum of the given date and the given amount of seconds.
static java.util.Date addWeeks(java.util.Date date, int weeks)
          Returns a new date instance which is a sum of the given date and the given amount of weeks.
static java.util.Date addYears(java.util.Date date, int years)
          Returns a new date instance which is a sum of the given date and the given amount of years.
static int daysBetween(java.util.Date start, java.util.Date end)
          Returns the amount of days between two given dates.
static java.lang.String formatDate(java.util.Date date, java.lang.String pattern)
          Format the given date in the given pattern with system default timezone.
static java.lang.String formatDateWithTimezone(java.util.Date date, java.lang.String pattern, java.lang.Object timezone)
          Format the given date in the given pattern with the given timezone.
static java.lang.String getDayOfWeek(java.lang.Integer dayOfWeekNumber)
          Returns the day of week name from the mapping associated with the given day of week number in ISO 8601 order (Monday first) for the current locale.
static java.util.Map<java.lang.String,java.lang.Integer> getDaysOfWeek()
          Returns a mapping of day of week names in ISO 8601 order (Monday first) for the current locale.
static java.lang.String getMonth(java.lang.Integer monthNumber)
          Returns the month name from the mapping associated with the given month number for the current locale.
static java.util.Map<java.lang.String,java.lang.Integer> getMonths()
          Returns a mapping of month names by month numbers for the current locale.
static java.lang.String getShortDayOfWeek(java.lang.Integer dayOfWeekNumber)
          Returns the short day of week name from the mapping associated with the given day of week number in ISO 8601 order (Monday first) for the current locale.
static java.util.Map<java.lang.String,java.lang.Integer> getShortDaysOfWeek()
          Returns a mapping of short day of week names in ISO 8601 order (Monday first) for the current locale.
static java.lang.String getShortMonth(java.lang.Integer monthNumber)
          Returns the short month name from the mapping associated with the given month number for the current locale.
static java.util.Map<java.lang.String,java.lang.Integer> getShortMonths()
          Returns a mapping of short month names by month numbers for the current locale.
static long hoursBetween(java.util.Date start, java.util.Date end)
          Returns the amount of hours between two given dates.
static long minutesBetween(java.util.Date start, java.util.Date end)
          Returns the amount of minutes between two given dates.
static int monthsBetween(java.util.Date start, java.util.Date end)
          Returns the amount of months between two given dates.
static long secondsBetween(java.util.Date start, java.util.Date end)
          Returns the amount of seconds between two given dates.
static int weeksBetween(java.util.Date start, java.util.Date end)
          Returns the amount of weeks between two given dates.
static int yearsBetween(java.util.Date start, java.util.Date end)
          Returns the amount of years between two given dates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

formatDate

public static java.lang.String formatDate(java.util.Date date,
                                          java.lang.String pattern)
Format the given date in the given pattern with system default timezone. This is useful when you want to format dates in for example the title attribute of an UI component, or the itemLabel attribute of select item, or wherever you can't use the <f:convertDateTime> tag. The format locale will be set to the one as obtained by Faces.getLocale().

Parameters:
date - The date to be formatted in the given pattern.
pattern - The pattern to format the given date in.
Returns:
The date which is formatted in the given pattern.
Throws:
java.lang.NullPointerException - When the pattern is null.
See Also:
formatDateWithTimezone(Date, String, Object)

formatDateWithTimezone

public static java.lang.String formatDateWithTimezone(java.util.Date date,
                                                      java.lang.String pattern,
                                                      java.lang.Object timezone)
Format the given date in the given pattern with the given timezone. This is useful when you want to format dates in for example the title attribute of an UI component, or the itemLabel attribute of select item, or wherever you can't use the <f:convertDateTime> tag. The format locale will be set to the one as obtained by Faces.getLocale().

Parameters:
date - The date to be formatted in the given pattern.
pattern - The pattern to format the given date in.
timezone - The timezone to format the given date with, can be either timezone ID as string or TimeZone object.
Returns:
The date which is formatted in the given pattern.
Throws:
java.lang.NullPointerException - When the pattern is null.

addYears

public static java.util.Date addYears(java.util.Date date,
                                      int years)
Returns a new date instance which is a sum of the given date and the given amount of years.

Parameters:
date - The date to add the given amount of years to.
years - The amount of years to be added to the given date. It can be negative.
Returns:
A new date instance which is a sum of the given date and the given amount of years.
Throws:
java.lang.NullPointerException - When the date is null.

addMonths

public static java.util.Date addMonths(java.util.Date date,
                                       int months)
Returns a new date instance which is a sum of the given date and the given amount of months.

Parameters:
date - The date to add the given amount of months to.
months - The amount of months to be added to the given date. It can be negative.
Returns:
A new date instance which is a sum of the given date and the given amount of months.
Throws:
java.lang.NullPointerException - When the date is null.

addWeeks

public static java.util.Date addWeeks(java.util.Date date,
                                      int weeks)
Returns a new date instance which is a sum of the given date and the given amount of weeks.

Parameters:
date - The date to add the given amount of weeks to.
weeks - The amount of weeks to be added to the given date. It can be negative.
Returns:
A new date instance which is a sum of the given date and the given amount of weeks.
Throws:
java.lang.NullPointerException - When the date is null.

addDays

public static java.util.Date addDays(java.util.Date date,
                                     int days)
Returns a new date instance which is a sum of the given date and the given amount of days.

Parameters:
date - The date to add the given amount of days to.
days - The amount of days to be added to the given date. It can be negative.
Returns:
A new date instance which is a sum of the given date and the given amount of days.
Throws:
java.lang.NullPointerException - When the date is null.

addHours

public static java.util.Date addHours(java.util.Date date,
                                      int hours)
Returns a new date instance which is a sum of the given date and the given amount of hours.

Parameters:
date - The date to add the given amount of hours to.
hours - The amount of hours to be added to the given date. It can be negative.
Returns:
A new date instance which is a sum of the given date and the given amount of hours.
Throws:
java.lang.NullPointerException - When the date is null.

addMinutes

public static java.util.Date addMinutes(java.util.Date date,
                                        int minutes)
Returns a new date instance which is a sum of the given date and the given amount of minutes.

Parameters:
date - The date to add the given amount of minutes to.
minutes - The amount of minutes to be added to the given date. It can be negative.
Returns:
A new date instance which is a sum of the given date and the given amount of minutes.
Throws:
java.lang.NullPointerException - When the date is null.

addSeconds

public static java.util.Date addSeconds(java.util.Date date,
                                        int seconds)
Returns a new date instance which is a sum of the given date and the given amount of seconds.

Parameters:
date - The date to add the given amount of seconds to.
seconds - The amount of seconds to be added to the given date. It can be negative.
Returns:
A new date instance which is a sum of the given date and the given amount of seconds.
Throws:
java.lang.NullPointerException - When the date is null.

yearsBetween

public static int yearsBetween(java.util.Date start,
                               java.util.Date end)
Returns the amount of years between two given dates. This will be negative when the end date is before the start date.

Parameters:
start - The start date.
end - The end date.
Returns:
The amount of years between two given dates.
Throws:
java.lang.NullPointerException - When a date is null.

monthsBetween

public static int monthsBetween(java.util.Date start,
                                java.util.Date end)
Returns the amount of months between two given dates. This will be negative when the end date is before the start date.

Parameters:
start - The start date.
end - The end date.
Returns:
The amount of months between two given dates.
Throws:
java.lang.NullPointerException - When a date is null.

weeksBetween

public static int weeksBetween(java.util.Date start,
                               java.util.Date end)
Returns the amount of weeks between two given dates. This will be negative when the end date is before the start date.

Parameters:
start - The start date.
end - The end date.
Returns:
The amount of weeks between two given dates.
Throws:
java.lang.NullPointerException - When a date is null.

daysBetween

public static int daysBetween(java.util.Date start,
                              java.util.Date end)
Returns the amount of days between two given dates. This will be negative when the end date is before the start date.

Parameters:
start - The start date.
end - The end date.
Returns:
The amount of days between two given dates.
Throws:
java.lang.NullPointerException - When a date is null.

hoursBetween

public static long hoursBetween(java.util.Date start,
                                java.util.Date end)
Returns the amount of hours between two given dates. This will be negative when the end date is before the start date.

Parameters:
start - The start date.
end - The end date.
Returns:
The amount of hours between two given dates.
Throws:
java.lang.NullPointerException - When a date is null.

minutesBetween

public static long minutesBetween(java.util.Date start,
                                  java.util.Date end)
Returns the amount of minutes between two given dates. This will be negative when the end date is before the start date.

Parameters:
start - The start date.
end - The end date.
Returns:
The amount of minutes between two given dates.
Throws:
java.lang.NullPointerException - When a date is null.

secondsBetween

public static long secondsBetween(java.util.Date start,
                                  java.util.Date end)
Returns the amount of seconds between two given dates. This will be negative when the end date is before the start date.

Parameters:
start - The start date.
end - The end date.
Returns:
The amount of seconds between two given dates.
Throws:
java.lang.NullPointerException - When a date is null.

getMonths

public static java.util.Map<java.lang.String,java.lang.Integer> getMonths()
Returns a mapping of month names by month numbers for the current locale. For example: "January=1", "February=2", etc. This is useful if you want to for example populate a <f:selectItems> which shows all months. The locale is obtained by Faces.getLocale(). The mapping is per locale stored in a local cache to improve retrieving performance.

Returns:
Month names for the current locale.
See Also:
DateFormatSymbols.getMonths()

getShortMonths

public static java.util.Map<java.lang.String,java.lang.Integer> getShortMonths()
Returns a mapping of short month names by month numbers for the current locale. For example: "Jan=1", "Feb=2", etc. This is useful if you want to for example populate a <f:selectItems> which shows all short months. The locale is obtained by Faces.getLocale(). The mapping is per locale stored in a local cache to improve retrieving performance.

Returns:
Short month names for the current locale.
See Also:
DateFormatSymbols.getShortMonths()

getDaysOfWeek

public static java.util.Map<java.lang.String,java.lang.Integer> getDaysOfWeek()
Returns a mapping of day of week names in ISO 8601 order (Monday first) for the current locale. For example: "Monday=1", "Tuesday=2", etc. This is useful if you want to for example populate a <f:selectItems> which shows all days of week. The locale is obtained by Faces.getLocale(). The mapping is per locale stored in a local cache to improve retrieving performance.

Returns:
Day of week names for the current locale.
See Also:
DateFormatSymbols.getWeekdays()

getShortDaysOfWeek

public static java.util.Map<java.lang.String,java.lang.Integer> getShortDaysOfWeek()
Returns a mapping of short day of week names in ISO 8601 order (Monday first) for the current locale. For example: "Mon=1", "Tue=2", etc. This is useful if you want to for example populate a <f:selectItems> which shows all short days of week. The locale is obtained by Faces.getLocale(). The mapping is per locale stored in a local cache to improve retrieving performance.

Returns:
Short day of week names for the current locale.
See Also:
DateFormatSymbols.getShortWeekdays()

getMonth

public static java.lang.String getMonth(java.lang.Integer monthNumber)
Returns the month name from the mapping associated with the given month number for the current locale. For example: "1=January", "2=February", etc. The locale is obtained by Faces.getLocale().

Parameters:
monthNumber - The month number to return the month name from the mapping for.
Returns:
The month name form the mapping associated with the given month number.
Since:
1.4

getShortMonth

public static java.lang.String getShortMonth(java.lang.Integer monthNumber)
Returns the short month name from the mapping associated with the given month number for the current locale. For example: "1=Jan", "2=Feb", etc. The locale is obtained by Faces.getLocale().

Parameters:
monthNumber - The month number to return the short month name from the mapping for.
Returns:
The short month name form the mapping associated with the given month number.
Since:
1.4

getDayOfWeek

public static java.lang.String getDayOfWeek(java.lang.Integer dayOfWeekNumber)
Returns the day of week name from the mapping associated with the given day of week number in ISO 8601 order (Monday first) for the current locale. For example: "1=Monday", "2=Tuesday", etc. The locale is obtained by Faces.getLocale().

Parameters:
dayOfWeekNumber - The day of week number to return the day of week name from the mapping for.
Returns:
The day of week name from the mapping associated with the given day of week number.
Since:
1.4

getShortDayOfWeek

public static java.lang.String getShortDayOfWeek(java.lang.Integer dayOfWeekNumber)
Returns the short day of week name from the mapping associated with the given day of week number in ISO 8601 order (Monday first) for the current locale. For example: "1=Mon", "2=Tue", etc. The locale is obtained by Faces.getLocale().

Parameters:
dayOfWeekNumber - The day of week number to return the short day of week name from the mapping for.
Returns:
The short day of week name from the mapping associated with the given day of week number.
Since:
1.4