Class FlowableExpressionTimeUtils
java.lang.Object
com.flowable.platform.expressions.FlowableExpressionTimeUtils
public class FlowableExpressionTimeUtils
extends java.lang.Object
Expression Bean Name: flwTimeUtils
Provides a number of date and time utilities which can be used in expressions.
Please note that all operations use UTC as time zone.
Example: #{flwTimeUtils.currentDate()}
Example: #{flwTimeUtils.plusDays(now(), 10)}
-
Constructor Summary
Constructors Constructor Description FlowableExpressionTimeUtils() -
Method Summary
Modifier and Type Method Description java.util.DateasDate(java.time.Instant instant)Converts an instant to a date.java.lang.ObjectatTime(java.lang.Object dateOrInstant, int hours, int minutes, int seconds)Sets the time of an instant to the specified hours, minutes and seconds.java.lang.ObjectatTimeWithTimeZone(java.lang.Object dateOrInstant, int hours, int minutes, int seconds, java.lang.String timezoneId)Sets the time of an instant or date to the specified hours, minutes and seconds and returns that time in a specified time zone.java.lang.ObjectatTimeZone(java.lang.Object dateOrInstant, java.lang.String timeZoneId)Returns an instant at a specified time zone.java.time.InstantcurrentDate()Returns the current date at 00:00 AM UTC.java.util.DatedateFromTimestamp(long timestamp)Returns a date from the number of seconds that have passed since the first of January 1970 (Unix Timestamp).java.util.DatefullDateTimeDate(int year, int month, int day, int hour, int minute, int second)Constructs anDatebased on a given year, month, day, hour, minute and second.java.time.InstantfullDateTimeInstant(int year, int month, int day, int hour, int minute, int second)Constructs anInstantbased on a given year, month, day, hour, minute and second.java.util.List<java.lang.String>getAvailableTimeZoneIds()Receives a list of all available timeZoneIds maintained as specified by the IANA.intgetField(java.lang.Object dateOrInstant, java.lang.String chronoFieldString)Obtains a "slice of time" by specifying aChronoFieldasString.longgetFieldFromDurationBetweenDates(java.lang.Object firstDateOrInstant, java.lang.Object secondDateOrInstant, java.lang.String chronoUnitString)Gets the duration between twoDateorInstantand extracts in a certain unit.longgetTimeZoneOffset(java.lang.Object dateOrInstant, java.lang.String timeZoneId)Calculates the number of seconds a specific point in time at a specified time zone is set off from UTC.java.time.InstantinstantFromTimestamp(long timestamp)Returns an instant from the number of seconds that have passed since the first of January 1970 (Unix Timestamp).booleanisAfter(java.lang.Object dateOrInstant, java.lang.Object otherDateOrInstant)Checks if theDateorInstantis after anotherDateorInstant.booleanisAfterTime(java.lang.Object dateOrInstant, java.lang.String timeZoneId, int hours, int minutes, int seconds)Checks if anDateorInstantis after a certain time in a given time zone.booleanisBefore(java.lang.Object dateOrInstant, java.lang.Object otherDateOrInstant)Checks if the instant is before anotherDateorInstant.booleanisBeforeTime(java.lang.Object dateOrInstant, java.lang.String timeZoneId, int hours, int minutes, int seconds)Checks if anDateorInstantis before a certain time in a given time zone.booleanisWeekend(java.lang.Object dateOrInstant)Determines whether the current day is a weekend.java.lang.ObjectminusDays(java.lang.Object dateOrInstant, long days)Subtracts hours from an instant.java.lang.ObjectminusDuration(java.lang.Object dateOrInstant, java.lang.String iso8601Duration)Subtracts an ISO8601-encoded duration from aDateorInstant.java.lang.ObjectminusHours(java.lang.Object dateOrInstant, long hours)Subtracts hours from anDateorInstant.java.lang.ObjectminusMinutes(java.lang.Object dateOrInstant, long minutes)Subtracts minutes from anDateorInstant.java.lang.ObjectminusMonths(java.lang.Object dateOrInstant, long months)Subtracts months from aDateorInstant.java.lang.ObjectminusSeconds(java.lang.Object dateOrInstant, long seconds)Subtracts seconds from anDateorInstant.java.lang.ObjectminusWeeks(java.lang.Object dateOrInstant, long weeks)Subtracts weeks to anDateorInstant.java.lang.ObjectminusYears(java.lang.Object dateOrInstant, long years)Subtracts years to aDateorInstant.java.time.Instantnow()Returns the current date and time in UTC.java.lang.ObjectplusDays(java.lang.Object dateOrInstant, long days)Adds days to aDateorInstant.java.lang.ObjectplusDuration(java.lang.Object dateOrInstant, java.lang.String iso8601Duration)Adds an ISO8601-encoded duration to aDateorInstant.java.lang.ObjectplusHours(java.lang.Object dateOrInstant, long hours)Adds hours to aDateorInstant.java.lang.ObjectplusMinutes(java.lang.Object dateOrInstant, long minutes)Adds minutes to an instant.java.lang.ObjectplusMonths(java.lang.Object dateOrInstant, long months)Adds months to aDateorInstant.java.lang.ObjectplusSeconds(java.lang.Object dateOrInstant, long seconds)Adds seconds to anDateorInstant.java.lang.ObjectplusWeeks(java.lang.Object dateOrInstant, long weeks)Adds weeks to aDateorInstant.java.lang.ObjectplusYears(java.lang.Object dateOrInstant, long years)Adds years from anDateorInstant.longsecondsBetweenDates(java.lang.Object firstDateOrInstant, java.lang.Object secondDateOrInstant)Returns the number of seconds between twoDateorInstant.longsecondsOfDuration(java.lang.String iso8601Duration)Gets the number of seconds in a ISO duration string, e.g.
-
Constructor Details
-
FlowableExpressionTimeUtils
public FlowableExpressionTimeUtils()
-
-
Method Details
-
asDate
public java.util.Date asDate(java.time.Instant instant)Converts an instant to a date. This is useful in places where the old Java Date API is still used.- Parameters:
instant- the instant to be converted- Returns:
- A
Datebased on the provided instant.
-
atTime
public java.lang.Object atTime(java.lang.Object dateOrInstant, int hours, int minutes, int seconds)Sets the time of an instant to the specified hours, minutes and seconds. The ZoneOffset is UTC.- Parameters:
dateOrInstant- BaseDateorInstanthours- the hours to be setminutes- the minutes to be setseconds- the seconds to be set- Returns:
- A new
InstantorDateat the specified time.
-
atTimeWithTimeZone
public java.lang.Object atTimeWithTimeZone(java.lang.Object dateOrInstant, int hours, int minutes, int seconds, java.lang.String timezoneId)Sets the time of an instant or date to the specified hours, minutes and seconds and returns that time in a specified time zone. Example: Get the current date and time (now) in UTC, set the time to 10:00:00 AM and return the time in the time zone "Europe/Zurich" which will have an offset of either 1 or 2 hours, depending on the time of the year.- Parameters:
dateOrInstant- baseDateorInstanthours- the hours to be setminutes- the minutes to be setseconds- the seconds to be settimezoneId- the time zone- Returns:
- A new
DateorInstantat the specified time (in UTC) at the specified time zone.
-
atTimeZone
public java.lang.Object atTimeZone(java.lang.Object dateOrInstant, java.lang.String timeZoneId)Returns an instant at a specified time zone.
This is useful in application where more than one time zone is involved and users in different time zones
receive dates offset to their specific time zones.
Example:#{flwTimeUtils.atTimeZone(now(), 'Europe/Zurich')}will return the current time in Zurich
A list of all available time zones can be received withgetAvailableTimeZoneIds()
A more or less up-to-date list can also be found here: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones ATTENTION: This is for display purposes only, never store a date in a specific time zone!- Parameters:
dateOrInstant- baseDateorInstanttimeZoneId- the timeZone ID- Returns:
- An
DateorInstant, offset by the specified timeZoneId
-
getAvailableTimeZoneIds
public java.util.List<java.lang.String> getAvailableTimeZoneIds()Receives a list of all available timeZoneIds maintained as specified by the IANA.
Use this method if you want to provide a selection of time zones to an end user.- Returns:
- A list of valid time zones usable with
atTimeZone(Object, String)
-
getField
public int getField(java.lang.Object dateOrInstant, java.lang.String chronoFieldString)Obtains a "slice of time" by specifying aChronoFieldasString.
The method supports both, the display name and the enum name of ChronoFields.
Example:#{flwTimeUtils.getField(now(), "DAY_OF_WEEK")}to obtain the current day of the week
Example:#{flwTimeUtils.getField(now(), "SECOND_OF_MINUTE")}to obtain the seconds in the current minute
Example:#{flwTimeUtils.getField(now(), "AlignedWeekOfYear")}to obtain the calendar week. This example uses the display name of the Chrono Field.
A list of all Chrono Fields can be found here:
https://docs.oracle.com/javase/8/docs/api/java/time/temporal/ChronoField.html- Parameters:
dateOrInstant- baseDateorInstantchronoFieldString- the name of a chrono field, seeChronoField- Returns:
- An
intrepresenting the desiredChronoFieldof the instance in UTC.
-
isWeekend
public boolean isWeekend(java.lang.Object dateOrInstant)Determines whether the current day is a weekend.- Parameters:
dateOrInstant- aDateorInstant- Returns:
- A
Booleanwhich indicates whether the current day is a weekend
-
fullDateTimeInstant
public java.time.Instant fullDateTimeInstant(int year, int month, int day, int hour, int minute, int second)Constructs anInstantbased on a given year, month, day, hour, minute and second.- Parameters:
year- the year to usemonth- the month to useday- the day to usehour- the hour to useminute- the minute to usesecond- the second to use- Returns:
- An
Instant
-
fullDateTimeDate
public java.util.Date fullDateTimeDate(int year, int month, int day, int hour, int minute, int second)Constructs anDatebased on a given year, month, day, hour, minute and second.- Parameters:
year- the year to usemonth- the month to useday- the day to usehour- the hour to useminute- the minute to usesecond- the second to use- Returns:
- An
Date
-
plusSeconds
public java.lang.Object plusSeconds(java.lang.Object dateOrInstant, long seconds)Adds seconds to anDateorInstant.- Parameters:
dateOrInstant- the basisDateorInstantseconds- the number of seconds to add- Returns:
- A new
DateorInstant
-
plusMinutes
public java.lang.Object plusMinutes(java.lang.Object dateOrInstant, long minutes)Adds minutes to an instant.- Parameters:
dateOrInstant- the basisDateorInstantminutes- the number of minutes to add- Returns:
- A new
DateorInstant
-
plusHours
public java.lang.Object plusHours(java.lang.Object dateOrInstant, long hours)Adds hours to aDateorInstant.- Parameters:
dateOrInstant- the basisDateorInstanthours- the number of hours to add- Returns:
- A new
DateorInstant
-
plusDays
public java.lang.Object plusDays(java.lang.Object dateOrInstant, long days)Adds days to aDateorInstant.- Parameters:
dateOrInstant- the basisDateorInstantdays- the number of days to add- Returns:
- A new
Instant
-
plusWeeks
public java.lang.Object plusWeeks(java.lang.Object dateOrInstant, long weeks)Adds weeks to aDateorInstant.- Parameters:
dateOrInstant- the basisDateorInstantweeks- the number of weeks to add- Returns:
- A new
DateorInstant
-
plusMonths
public java.lang.Object plusMonths(java.lang.Object dateOrInstant, long months)Adds months to aDateorInstant.- Parameters:
dateOrInstant- the basisDateorInstantmonths- the number of months to add- Returns:
- A new
DateorInstant
-
plusYears
public java.lang.Object plusYears(java.lang.Object dateOrInstant, long years)Adds years from anDateorInstant.- Parameters:
dateOrInstant- the basisDateorInstantyears- the number of years to add- Returns:
- A new
DateorInstant
-
plusDuration
public java.lang.Object plusDuration(java.lang.Object dateOrInstant, java.lang.String iso8601Duration)Adds an ISO8601-encoded duration to aDateorInstant.
Example:#{flwTimeUtils.plusDuration(now(), 'P1Y')}adds a year
Example:#{flwTimeUtils.plusDuration(now(), 'P14D')}adds 14 days
Example:#{flwTimeUtils.plusDuration(now(), 'PT30M10S')}adds 30 minutes and ten seconds- Parameters:
dateOrInstant- the basisDateorInstantiso8601Duration- the duration to be added to the instant- Returns:
- A new
DateorInstant
-
minusSeconds
public java.lang.Object minusSeconds(java.lang.Object dateOrInstant, long seconds)Subtracts seconds from anDateorInstant.- Parameters:
dateOrInstant- the basisDateorInstantseconds- the number of seconds to subtract- Returns:
- A new
DateorInstant
-
minusMinutes
public java.lang.Object minusMinutes(java.lang.Object dateOrInstant, long minutes)Subtracts minutes from anDateorInstant.- Parameters:
dateOrInstant- the basisDateorInstantminutes- the number of minutes to subtract- Returns:
- A new
DateorInstant
-
minusHours
public java.lang.Object minusHours(java.lang.Object dateOrInstant, long hours)Subtracts hours from anDateorInstant.- Parameters:
dateOrInstant- the basisDateorInstanthours- the number of hours to subtract- Returns:
- A new
DateorInstant
-
minusDays
public java.lang.Object minusDays(java.lang.Object dateOrInstant, long days)Subtracts hours from an instant.- Parameters:
dateOrInstant- the basisDateorInstantdays- the number of days to subtract- Returns:
- A new
DateorInstant
-
minusWeeks
public java.lang.Object minusWeeks(java.lang.Object dateOrInstant, long weeks)Subtracts weeks to anDateorInstant.- Parameters:
dateOrInstant- the basisDateorInstantweeks- the number of weeks to subtract- Returns:
- A new
DateorInstant
-
minusMonths
public java.lang.Object minusMonths(java.lang.Object dateOrInstant, long months)Subtracts months from aDateorInstant.- Parameters:
dateOrInstant- the basisDateorInstantmonths- the number of months to subtract- Returns:
- A new
DateorInstant
-
minusYears
public java.lang.Object minusYears(java.lang.Object dateOrInstant, long years)Subtracts years to aDateorInstant.- Parameters:
dateOrInstant- the basisDateorInstantyears- the number of years to subtract- Returns:
- A new
DateorInstant
-
minusDuration
public java.lang.Object minusDuration(java.lang.Object dateOrInstant, java.lang.String iso8601Duration)Subtracts an ISO8601-encoded duration from aDateorInstant. Example:#{flwTimeUtils.minusDuration(now(), 'P1Y')}subtracts a year Example:#{flwTimeUtils.minusDuration(now(), 'P14D')}subtracts 14 days Example:#{flwTimeUtils.minusDuration(now(), 'PT30M10S')}subtracts 30 minutes and ten seconds- Parameters:
dateOrInstant- the basisDateorInstantiso8601Duration- the duration to be added- Returns:
- A new
DateorInstant
-
secondsOfDuration
public long secondsOfDuration(java.lang.String iso8601Duration)Gets the number of seconds in a ISO duration string, e.g. PT60M returns 3600.- Parameters:
iso8601Duration-- Returns:
- Number of seconds in the given duration
-
currentDate
public java.time.Instant currentDate()Returns the current date at 00:00 AM UTC.- Returns:
- An
Instantof the current date at 00:00 AM UTC.
-
isBefore
public boolean isBefore(java.lang.Object dateOrInstant, java.lang.Object otherDateOrInstant)Checks if the instant is before anotherDateorInstant.- Parameters:
dateOrInstant- firstDateorInstantto compare tootherDateOrInstant-DateorInstantto which to compare- Returns:
- Whether or not the first
DateorInstantis before the secondDateorInstant
-
isAfter
public boolean isAfter(java.lang.Object dateOrInstant, java.lang.Object otherDateOrInstant)Checks if theDateorInstantis after anotherDateorInstant.- Parameters:
dateOrInstant- firstDateorInstantto compare tootherDateOrInstant-DateorInstantto which to compare- Returns:
- Whether or not the first
DateorInstantis after the secondDateorInstant
-
isBeforeTime
public boolean isBeforeTime(java.lang.Object dateOrInstant, java.lang.String timeZoneId, int hours, int minutes, int seconds)Checks if anDateorInstantis before a certain time in a given time zone.- Parameters:
dateOrInstant-DateorInstantto compare the time totimeZoneId- the time zone of the given instanthours- hour within the same dayminutes- minutes within the hourseconds- seconds within the minute- Returns:
- Whether or not the given
DateorInstantis before the given time in a certain time zone
-
isAfterTime
public boolean isAfterTime(java.lang.Object dateOrInstant, java.lang.String timeZoneId, int hours, int minutes, int seconds)Checks if anDateorInstantis after a certain time in a given time zone.- Parameters:
dateOrInstant-DateorInstantto compare the time totimeZoneId- the time zone of the given instanthours- hour within the same dayminutes- minutes within the hourseconds- seconds within the minute- Returns:
- Whether or not the given
DateorInstantis after the given time in a certain time zone
-
secondsBetweenDates
public long secondsBetweenDates(java.lang.Object firstDateOrInstant, java.lang.Object secondDateOrInstant)Returns the number of seconds between twoDateorInstant.- Parameters:
firstDateOrInstant- the firstDateorInstantsecondDateOrInstant- the secondDateorInstant- Returns:
- Number of seconds between the two
DateorInstant
-
getFieldFromDurationBetweenDates
public long getFieldFromDurationBetweenDates(java.lang.Object firstDateOrInstant, java.lang.Object secondDateOrInstant, java.lang.String chronoUnitString)Gets the duration between twoDateorInstantand extracts in a certain unit. The following units are supported: Nanos, Micros, Millis, Seconds, Hours, HalfDays, Days, Weeks, Months, Years, Decades, Centuries, Millenia Please note that the number will always be an integer, i.e. the number will always be rounded.- Parameters:
firstDateOrInstant- the firstDateorInstantsecondDateOrInstant- the secondDateorInstantchronoUnitString- chrono Unit to be extracted, e.g. 'Seconds' or 'Days'- Returns:
- Duration between two
DateorInstantin the specific unit.
-
getTimeZoneOffset
public long getTimeZoneOffset(java.lang.Object dateOrInstant, java.lang.String timeZoneId)Calculates the number of seconds a specific point in time at a specified time zone is set off from UTC. You have to provide anDateorInstantbecause, depending on the time of the year, offsets can vary. This is useful to calculate the time in another time zone. Please note that you should never store the result of such calculations since Instants should always be stored in UTC. Example: #{flwTimeUtils.getTimZoneOffset(now(), "Pacific/Honolulu)} calculates the number of seconds between Honolulu and UTC time Example: #{flwTimeUtils.plusSeconds(now(), flwTimeUtils.getTimeZoneOffset(now(), "Europe/Zurich")} returns the current time in Zurich.- Parameters:
dateOrInstant- the date you want to check the offset attimeZoneId- the time zone- Returns:
- The offset in seconds
-
instantFromTimestamp
public java.time.Instant instantFromTimestamp(long timestamp)Returns an instant from the number of seconds that have passed since the first of January 1970 (Unix Timestamp).- Parameters:
timestamp-- Returns:
- Instant at the specified time stamp.
-
dateFromTimestamp
public java.util.Date dateFromTimestamp(long timestamp)Returns a date from the number of seconds that have passed since the first of January 1970 (Unix Timestamp).- Parameters:
timestamp-- Returns:
Dateat the specified time stamp.
-
now
public java.time.Instant now()Returns the current date and time in UTC.- Returns:
- Current date and time
-