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.Date
asDate(java.time.Instant instant)
Converts an instant to a date.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.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.java.lang.Object
atTimeZone(java.lang.Object dateOrInstant, java.lang.String timeZoneId)
Returns an instant at a specified time zone.java.time.Instant
currentDate()
Returns the current date at 00:00 AM UTC.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).java.util.Date
fullDateTimeDate(int year, int month, int day, int hour, int minute, int second)
Constructs anDate
based on a given year, month, day, hour, minute and second.java.time.Instant
fullDateTimeInstant(int year, int month, int day, int hour, int minute, int second)
Constructs anInstant
based 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.int
getField(java.lang.Object dateOrInstant, java.lang.String chronoFieldString)
Obtains a "slice of time" by specifying aChronoField
asString
.long
getFieldFromDurationBetweenDates(java.lang.Object firstDateOrInstant, java.lang.Object secondDateOrInstant, java.lang.String chronoUnitString)
Gets the duration between twoDate
orInstant
and extracts in a certain unit.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.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).boolean
isAfter(java.lang.Object dateOrInstant, java.lang.Object otherDateOrInstant)
Checks if theDate
orInstant
is after anotherDate
orInstant
.boolean
isAfterTime(java.lang.Object dateOrInstant, java.lang.String timeZoneId, int hours, int minutes, int seconds)
Checks if anDate
orInstant
is after a certain time in a given time zone.boolean
isBefore(java.lang.Object dateOrInstant, java.lang.Object otherDateOrInstant)
Checks if the instant is before anotherDate
orInstant
.boolean
isBeforeTime(java.lang.Object dateOrInstant, java.lang.String timeZoneId, int hours, int minutes, int seconds)
Checks if anDate
orInstant
is before a certain time in a given time zone.boolean
isWeekend(java.lang.Object dateOrInstant)
Determines whether the current day is a weekend.java.lang.Object
minusDays(java.lang.Object dateOrInstant, long days)
Subtracts hours from an instant.java.lang.Object
minusDuration(java.lang.Object dateOrInstant, java.lang.String iso8601Duration)
Subtracts an ISO8601-encoded duration from aDate
orInstant
.java.lang.Object
minusHours(java.lang.Object dateOrInstant, long hours)
Subtracts hours from anDate
orInstant
.java.lang.Object
minusMinutes(java.lang.Object dateOrInstant, long minutes)
Subtracts minutes from anDate
orInstant
.java.lang.Object
minusMonths(java.lang.Object dateOrInstant, long months)
Subtracts months from aDate
orInstant
.java.lang.Object
minusSeconds(java.lang.Object dateOrInstant, long seconds)
Subtracts seconds from anDate
orInstant
.java.lang.Object
minusWeeks(java.lang.Object dateOrInstant, long weeks)
Subtracts weeks to anDate
orInstant
.java.lang.Object
minusYears(java.lang.Object dateOrInstant, long years)
Subtracts years to aDate
orInstant
.java.time.Instant
now()
Returns the current date and time in UTC.java.lang.Object
plusDays(java.lang.Object dateOrInstant, long days)
Adds days to aDate
orInstant
.java.lang.Object
plusDuration(java.lang.Object dateOrInstant, java.lang.String iso8601Duration)
Adds an ISO8601-encoded duration to aDate
orInstant
.java.lang.Object
plusHours(java.lang.Object dateOrInstant, long hours)
Adds hours to aDate
orInstant
.java.lang.Object
plusMinutes(java.lang.Object dateOrInstant, long minutes)
Adds minutes to an instant.java.lang.Object
plusMonths(java.lang.Object dateOrInstant, long months)
Adds months to aDate
orInstant
.java.lang.Object
plusSeconds(java.lang.Object dateOrInstant, long seconds)
Adds seconds to anDate
orInstant
.java.lang.Object
plusWeeks(java.lang.Object dateOrInstant, long weeks)
Adds weeks to aDate
orInstant
.java.lang.Object
plusYears(java.lang.Object dateOrInstant, long years)
Adds years from anDate
orInstant
.long
secondsBetweenDates(java.lang.Object firstDateOrInstant, java.lang.Object secondDateOrInstant)
Returns the number of seconds between twoDate
orInstant
.long
secondsOfDuration(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
Date
based 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
- BaseDate
orInstant
hours
- the hours to be setminutes
- the minutes to be setseconds
- the seconds to be set- Returns:
- A new
Instant
orDate
at 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
- baseDate
orInstant
hours
- the hours to be setminutes
- the minutes to be setseconds
- the seconds to be settimezoneId
- the time zone- Returns:
- A new
Date
orInstant
at 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
- baseDate
orInstant
timeZoneId
- the timeZone ID- Returns:
- An
Date
orInstant
, 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 aChronoField
asString
.
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
- baseDate
orInstant
chronoFieldString
- the name of a chrono field, seeChronoField
- Returns:
- An
int
representing the desiredChronoField
of the instance in UTC.
-
isWeekend
public boolean isWeekend(java.lang.Object dateOrInstant)Determines whether the current day is a weekend.- Parameters:
dateOrInstant
- aDate
orInstant
- Returns:
- A
Boolean
which 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 anInstant
based 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 anDate
based 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 anDate
orInstant
.- Parameters:
dateOrInstant
- the basisDate
orInstant
seconds
- the number of seconds to add- Returns:
- A new
Date
orInstant
-
plusMinutes
public java.lang.Object plusMinutes(java.lang.Object dateOrInstant, long minutes)Adds minutes to an instant.- Parameters:
dateOrInstant
- the basisDate
orInstant
minutes
- the number of minutes to add- Returns:
- A new
Date
orInstant
-
plusHours
public java.lang.Object plusHours(java.lang.Object dateOrInstant, long hours)Adds hours to aDate
orInstant
.- Parameters:
dateOrInstant
- the basisDate
orInstant
hours
- the number of hours to add- Returns:
- A new
Date
orInstant
-
plusDays
public java.lang.Object plusDays(java.lang.Object dateOrInstant, long days)Adds days to aDate
orInstant
.- Parameters:
dateOrInstant
- the basisDate
orInstant
days
- 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 aDate
orInstant
.- Parameters:
dateOrInstant
- the basisDate
orInstant
weeks
- the number of weeks to add- Returns:
- A new
Date
orInstant
-
plusMonths
public java.lang.Object plusMonths(java.lang.Object dateOrInstant, long months)Adds months to aDate
orInstant
.- Parameters:
dateOrInstant
- the basisDate
orInstant
months
- the number of months to add- Returns:
- A new
Date
orInstant
-
plusYears
public java.lang.Object plusYears(java.lang.Object dateOrInstant, long years)Adds years from anDate
orInstant
.- Parameters:
dateOrInstant
- the basisDate
orInstant
years
- the number of years to add- Returns:
- A new
Date
orInstant
-
plusDuration
public java.lang.Object plusDuration(java.lang.Object dateOrInstant, java.lang.String iso8601Duration)Adds an ISO8601-encoded duration to aDate
orInstant
.
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 basisDate
orInstant
iso8601Duration
- the duration to be added to the instant- Returns:
- A new
Date
orInstant
-
minusSeconds
public java.lang.Object minusSeconds(java.lang.Object dateOrInstant, long seconds)Subtracts seconds from anDate
orInstant
.- Parameters:
dateOrInstant
- the basisDate
orInstant
seconds
- the number of seconds to subtract- Returns:
- A new
Date
orInstant
-
minusMinutes
public java.lang.Object minusMinutes(java.lang.Object dateOrInstant, long minutes)Subtracts minutes from anDate
orInstant
.- Parameters:
dateOrInstant
- the basisDate
orInstant
minutes
- the number of minutes to subtract- Returns:
- A new
Date
orInstant
-
minusHours
public java.lang.Object minusHours(java.lang.Object dateOrInstant, long hours)Subtracts hours from anDate
orInstant
.- Parameters:
dateOrInstant
- the basisDate
orInstant
hours
- the number of hours to subtract- Returns:
- A new
Date
orInstant
-
minusDays
public java.lang.Object minusDays(java.lang.Object dateOrInstant, long days)Subtracts hours from an instant.- Parameters:
dateOrInstant
- the basisDate
orInstant
days
- the number of days to subtract- Returns:
- A new
Date
orInstant
-
minusWeeks
public java.lang.Object minusWeeks(java.lang.Object dateOrInstant, long weeks)Subtracts weeks to anDate
orInstant
.- Parameters:
dateOrInstant
- the basisDate
orInstant
weeks
- the number of weeks to subtract- Returns:
- A new
Date
orInstant
-
minusMonths
public java.lang.Object minusMonths(java.lang.Object dateOrInstant, long months)Subtracts months from aDate
orInstant
.- Parameters:
dateOrInstant
- the basisDate
orInstant
months
- the number of months to subtract- Returns:
- A new
Date
orInstant
-
minusYears
public java.lang.Object minusYears(java.lang.Object dateOrInstant, long years)Subtracts years to aDate
orInstant
.- Parameters:
dateOrInstant
- the basisDate
orInstant
years
- the number of years to subtract- Returns:
- A new
Date
orInstant
-
minusDuration
public java.lang.Object minusDuration(java.lang.Object dateOrInstant, java.lang.String iso8601Duration)Subtracts an ISO8601-encoded duration from aDate
orInstant
. 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 basisDate
orInstant
iso8601Duration
- the duration to be added- Returns:
- A new
Date
orInstant
-
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
Instant
of 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 anotherDate
orInstant
.- Parameters:
dateOrInstant
- firstDate
orInstant
to compare tootherDateOrInstant
-Date
orInstant
to which to compare- Returns:
- Whether or not the first
Date
orInstant
is before the secondDate
orInstant
-
isAfter
public boolean isAfter(java.lang.Object dateOrInstant, java.lang.Object otherDateOrInstant)Checks if theDate
orInstant
is after anotherDate
orInstant
.- Parameters:
dateOrInstant
- firstDate
orInstant
to compare tootherDateOrInstant
-Date
orInstant
to which to compare- Returns:
- Whether or not the first
Date
orInstant
is after the secondDate
orInstant
-
isBeforeTime
public boolean isBeforeTime(java.lang.Object dateOrInstant, java.lang.String timeZoneId, int hours, int minutes, int seconds)Checks if anDate
orInstant
is before a certain time in a given time zone.- Parameters:
dateOrInstant
-Date
orInstant
to 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
Date
orInstant
is 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 anDate
orInstant
is after a certain time in a given time zone.- Parameters:
dateOrInstant
-Date
orInstant
to 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
Date
orInstant
is 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 twoDate
orInstant
.- Parameters:
firstDateOrInstant
- the firstDate
orInstant
secondDateOrInstant
- the secondDate
orInstant
- Returns:
- Number of seconds between the two
Date
orInstant
-
getFieldFromDurationBetweenDates
public long getFieldFromDurationBetweenDates(java.lang.Object firstDateOrInstant, java.lang.Object secondDateOrInstant, java.lang.String chronoUnitString)Gets the duration between twoDate
orInstant
and 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 firstDate
orInstant
secondDateOrInstant
- the secondDate
orInstant
chronoUnitString
- chrono Unit to be extracted, e.g. 'Seconds' or 'Days'- Returns:
- Duration between two
Date
orInstant
in 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 anDate
orInstant
because, 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:
Date
at the specified time stamp.
-
now
public java.time.Instant now()Returns the current date and time in UTC.- Returns:
- Current date and time
-