java.lang.Object
org.omnifaces.el.functions.Dates
Collection of EL functions for date and time: o:formatDate(), o:formatDateWithTimezone(),
o:addXxx() like o:addDays(), o:xxxBetween() like o:daysBetween(),
o:getMonths(), o:getShortMonths(), o:getDaysOfWeek(), o:getShortDaysOfWeek(),
o:getMonth(), o:getShortMonth(), o:getDayOfWeek() and o:getShortDayOfWeek().
Historical note: before OmniFaces 3.6, these functions accepted java.util.Date and java.util.TimeZone only.
Since OmniFaces 3.6, these functions also accept java.time.Temporal and java.time.ZoneId.
Since OmniFaces 4.7, these functions also accept java.lang.Long as epoch milli.
- Author:
- Bauke Scholtz
-
Method Summary
Modifier and TypeMethodDescriptionstatic <D> DaddDays(D date, int days) Returns a new date instance which is a sum of the given date and the given amount of days.static <D> DaddHours(D date, int hours) Returns a new date instance which is a sum of the given date and the given amount of hours.static <D> DaddMinutes(D date, int minutes) Returns a new date instance which is a sum of the given date and the given amount of minutes.static <D> DaddMonths(D date, int months) Returns a new date instance which is a sum of the given date and the given amount of months.static <D> DaddSeconds(D date, int seconds) Returns a new date instance which is a sum of the given date and the given amount of seconds.static <D> DaddWeeks(D date, int weeks) Returns a new date instance which is a sum of the given date and the given amount of weeks.static <D> DaddYears(D date, int years) Returns a new date instance which is a sum of the given date and the given amount of years.static <D> intdaysBetween(D start, D end) Returns the amount of days between two given dates.static <D> StringformatDate(D date, String pattern) Format the given date in the given pattern with the default timezone.static <D,Z> String formatDateWithTimezone(D date, String pattern, Z timezone) Format the given date in the given pattern with the given timezone.static StringgetDayOfWeek(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.Returns a mapping of day of week names in ISO 8601 order (Monday first) for the current locale.static StringReturns the month name from the mapping associated with the given month number for the current locale.Returns a mapping of month names by month numbers for the current locale.static StringgetShortDayOfWeek(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.Returns a mapping of short day of week names in ISO 8601 order (Monday first) for the current locale.static StringgetShortMonth(Integer monthNumber) Returns the short month name from the mapping associated with the given month number for the current locale.Returns a mapping of short month names by month numbers for the current locale.static <D> longhoursBetween(D start, D end) Returns the amount of hours between two given dates.static <D> longminutesBetween(D start, D end) Returns the amount of minutes between two given dates.static <D> intmonthsBetween(D start, D end) Returns the amount of months between two given dates.static <D> longsecondsBetween(D start, D end) Returns the amount of seconds between two given dates.static <D> intweeksBetween(D start, D end) Returns the amount of weeks between two given dates.static <D> intyearsBetween(D start, D end) Returns the amount of years between two given dates.
-
Method Details
-
formatDate
Format the given date in the given pattern with the default timezone. This is useful when you want to format dates in for example thetitleattribute of an UI component, or theitemLabelattribute of select item, or wherever you can't use the<f:convertDateTime>tag. The format locale will be set to the one as obtained byFaces.getLocale().- Type Parameters:
D- The date type, can beTemporal,Date,CalendarorLong.- 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:
NullPointerException- When the pattern isnull.IllegalArgumentException- When date is notTemporal,Date,CalendarorLong.- See Also:
-
formatDateWithTimezone
Format the given date in the given pattern with the given timezone. This is useful when you want to format dates in for example thetitleattribute of an UI component, or theitemLabelattribute of select item, or wherever you can't use the<f:convertDateTime>tag. The format locale will be set to the one as obtained byFaces.getLocale().- Type Parameters:
D- The date type, can beTemporal,Date,CalendarorLong.Z- The timezone type, can be eitherString,TimeZoneorZoneId.- 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.- Returns:
- The date which is formatted in the given pattern.
- Throws:
NullPointerException- When the pattern isnull.IllegalArgumentException- When date is notLong,Date,CalendarorTemporal, or when timezone is notString,TimeZoneorZoneId.
-
addYears
public static <D> D addYears(D date, int years) Returns a new date instance which is a sum of the given date and the given amount of years.- Type Parameters:
D- The date type, can beTemporal,Date,CalendarorLong.- 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:
NullPointerException- When the date isnull.IllegalArgumentException- When date is notTemporal,Date,CalendarorLong.
-
addMonths
public static <D> D addMonths(D date, int months) Returns a new date instance which is a sum of the given date and the given amount of months.- Type Parameters:
D- The date type, can beTemporal,Date,CalendarorLong.- 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:
NullPointerException- When the date isnull.IllegalArgumentException- When date is notTemporal,Date,CalendarorLong.
-
addWeeks
public static <D> D addWeeks(D date, int weeks) Returns a new date instance which is a sum of the given date and the given amount of weeks.- Type Parameters:
D- The date type, can beTemporal,Date,CalendarorLong.- 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:
NullPointerException- When the date isnull.IllegalArgumentException- When date is notTemporal,Date,CalendarorLong.
-
addDays
public static <D> D addDays(D date, int days) Returns a new date instance which is a sum of the given date and the given amount of days.- Type Parameters:
D- The date type, can beTemporal,Date,CalendarorLong.- 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:
NullPointerException- When the date isnull.IllegalArgumentException- When date is notTemporal,Date,CalendarorLong.
-
addHours
public static <D> D addHours(D date, int hours) Returns a new date instance which is a sum of the given date and the given amount of hours.- Type Parameters:
D- The date type, can beTemporal,Date,CalendarorLong.- 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:
NullPointerException- When the date isnull.IllegalArgumentException- When date is notTemporal,Date,CalendarorLong.
-
addMinutes
public static <D> D addMinutes(D date, int minutes) Returns a new date instance which is a sum of the given date and the given amount of minutes.- Type Parameters:
D- The date type, can beTemporal,Date,CalendarorLong.- 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:
NullPointerException- When the date isnull.IllegalArgumentException- When date is notTemporal,Date,CalendarorLong.
-
addSeconds
public static <D> D addSeconds(D date, int seconds) Returns a new date instance which is a sum of the given date and the given amount of seconds.- Type Parameters:
D- The date type, can beTemporal,Date,CalendarorLong.- 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:
NullPointerException- When the date isnull.IllegalArgumentException- When date is notTemporal,Date,CalendarorLong.
-
yearsBetween
public static <D> int yearsBetween(D start, D end) Returns the amount of years between two given dates. This will be negative when the end date is before the start date.- Type Parameters:
D- The date type, can beTemporal,Date,CalendarorLong.- Parameters:
start- The start date.end- The end date.- Returns:
- The amount of years between two given dates.
- Throws:
NullPointerException- When a date isnull.IllegalArgumentException- When date is notTemporal,Date,CalendarorLong.
-
monthsBetween
public static <D> int monthsBetween(D start, D end) Returns the amount of months between two given dates. This will be negative when the end date is before the start date.- Type Parameters:
D- The date type, can beTemporal,Date,CalendarorLong.- Parameters:
start- The start date.end- The end date.- Returns:
- The amount of months between two given dates.
- Throws:
NullPointerException- When a date isnull.IllegalArgumentException- When date is notTemporal,Date,CalendarorLong.
-
weeksBetween
public static <D> int weeksBetween(D start, D end) Returns the amount of weeks between two given dates. This will be negative when the end date is before the start date.- Type Parameters:
D- The date type, can beTemporal,Date,CalendarorLong.- Parameters:
start- The start date.end- The end date.- Returns:
- The amount of weeks between two given dates.
- Throws:
NullPointerException- When a date isnull.IllegalArgumentException- When date is notTemporal,Date,CalendarorLong.
-
daysBetween
public static <D> int daysBetween(D start, D end) Returns the amount of days between two given dates. This will be negative when the end date is before the start date.- Type Parameters:
D- The date type, can beTemporal,Date,CalendarorLong.- Parameters:
start- The start date.end- The end date.- Returns:
- The amount of days between two given dates.
- Throws:
NullPointerException- When a date isnull.IllegalArgumentException- When date is notTemporal,Date,CalendarorLong.
-
hoursBetween
public static <D> long hoursBetween(D start, D end) Returns the amount of hours between two given dates. This will be negative when the end date is before the start date.- Type Parameters:
D- The date type, can beTemporal,Date,CalendarorLong.- Parameters:
start- The start date.end- The end date.- Returns:
- The amount of hours between two given dates.
- Throws:
NullPointerException- When a date isnull.IllegalArgumentException- When date is notTemporal,Date,CalendarorLong.
-
minutesBetween
public static <D> long minutesBetween(D start, D end) Returns the amount of minutes between two given dates. This will be negative when the end date is before the start date.- Type Parameters:
D- The date type, can beTemporal,Date,CalendarorLong.- Parameters:
start- The start date.end- The end date.- Returns:
- The amount of minutes between two given dates.
- Throws:
NullPointerException- When a date isnull.IllegalArgumentException- When date is notTemporal,Date,CalendarorLong.
-
secondsBetween
public static <D> long secondsBetween(D start, D end) Returns the amount of seconds between two given dates. This will be negative when the end date is before the start date.- Type Parameters:
D- The date type, can beTemporal,Date,CalendarorLong.- Parameters:
start- The start date.end- The end date.- Returns:
- The amount of seconds between two given dates.
- Throws:
NullPointerException- When a date isnull.IllegalArgumentException- When date is notTemporal,Date,CalendarorLong.
-
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 byFaces.getLocale(). The mapping is per locale stored in a local cache to improve retrieving performance.- Returns:
- Month names for the current locale.
- See Also:
-
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 byFaces.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:
-
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 byFaces.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:
-
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 byFaces.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:
-
getMonth
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 byFaces.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
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 byFaces.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
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 byFaces.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
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 byFaces.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
-