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 an Date 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 an Instant 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 a ChronoField as String.
    long getFieldFromDurationBetweenDates​(java.lang.Object firstDateOrInstant, java.lang.Object secondDateOrInstant, java.lang.String chronoUnitString)
    Gets the duration between two Date or Instant 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 the Date or Instant is after another Date or Instant.
    boolean isAfterTime​(java.lang.Object dateOrInstant, java.lang.String timeZoneId, int hours, int minutes, int seconds)
    Checks if an Date or Instant 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 another Date or Instant.
    boolean isBeforeTime​(java.lang.Object dateOrInstant, java.lang.String timeZoneId, int hours, int minutes, int seconds)
    Checks if an Date or Instant 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 a Date or Instant.
    java.lang.Object minusHours​(java.lang.Object dateOrInstant, long hours)
    Subtracts hours from an Date or Instant.
    java.lang.Object minusMinutes​(java.lang.Object dateOrInstant, long minutes)
    Subtracts minutes from an Date or Instant.
    java.lang.Object minusMonths​(java.lang.Object dateOrInstant, long months)
    Subtracts months from a Date or Instant.
    java.lang.Object minusSeconds​(java.lang.Object dateOrInstant, long seconds)
    Subtracts seconds from an Date or Instant.
    java.lang.Object minusWeeks​(java.lang.Object dateOrInstant, long weeks)
    Subtracts weeks to an Date or Instant.
    java.lang.Object minusYears​(java.lang.Object dateOrInstant, long years)
    Subtracts years to a Date or Instant.
    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 a Date or Instant.
    java.lang.Object plusDuration​(java.lang.Object dateOrInstant, java.lang.String iso8601Duration)
    Adds an ISO8601-encoded duration to a Date or Instant.
    java.lang.Object plusHours​(java.lang.Object dateOrInstant, long hours)
    Adds hours to a Date or Instant.
    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 a Date or Instant.
    java.lang.Object plusSeconds​(java.lang.Object dateOrInstant, long seconds)
    Adds seconds to an Date or Instant.
    java.lang.Object plusWeeks​(java.lang.Object dateOrInstant, long weeks)
    Adds weeks to a Date or Instant.
    java.lang.Object plusYears​(java.lang.Object dateOrInstant, long years)
    Adds years from an Date or Instant.
    long secondsBetweenDates​(java.lang.Object firstDateOrInstant, java.lang.Object secondDateOrInstant)
    Returns the number of seconds between two Date or Instant.
    long secondsOfDuration​(java.lang.String iso8601Duration)
    Gets the number of seconds in a ISO duration string, e.g.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • 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 - Base Date or Instant
      hours - the hours to be set
      minutes - the minutes to be set
      seconds - the seconds to be set
      Returns:
      A new Instant or Date 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 - base Date or Instant
      hours - the hours to be set
      minutes - the minutes to be set
      seconds - the seconds to be set
      timezoneId - the time zone
      Returns:
      A new Date or Instant 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 with getAvailableTimeZoneIds()
      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 - base Date or Instant
      timeZoneId - the timeZone ID
      Returns:
      An Date or Instant, 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 a ChronoField as String.
      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 - base Date or Instant
      chronoFieldString - the name of a chrono field, see ChronoField
      Returns:
      An int representing the desired ChronoField of the instance in UTC.
    • isWeekend

      public boolean isWeekend​(java.lang.Object dateOrInstant)
      Determines whether the current day is a weekend.
      Parameters:
      dateOrInstant - a Date or Instant
      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 an Instant based on a given year, month, day, hour, minute and second.
      Parameters:
      year - the year to use
      month - the month to use
      day - the day to use
      hour - the hour to use
      minute - the minute to use
      second - 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 an Date based on a given year, month, day, hour, minute and second.
      Parameters:
      year - the year to use
      month - the month to use
      day - the day to use
      hour - the hour to use
      minute - the minute to use
      second - the second to use
      Returns:
      An Date
    • plusSeconds

      public java.lang.Object plusSeconds​(java.lang.Object dateOrInstant, long seconds)
      Adds seconds to an Date or Instant.
      Parameters:
      dateOrInstant - the basis Date or Instant
      seconds - the number of seconds to add
      Returns:
      A new Date or Instant
    • plusMinutes

      public java.lang.Object plusMinutes​(java.lang.Object dateOrInstant, long minutes)
      Adds minutes to an instant.
      Parameters:
      dateOrInstant - the basis Date or Instant
      minutes - the number of minutes to add
      Returns:
      A new Date or Instant
    • plusHours

      public java.lang.Object plusHours​(java.lang.Object dateOrInstant, long hours)
      Adds hours to a Date or Instant.
      Parameters:
      dateOrInstant - the basis Date or Instant
      hours - the number of hours to add
      Returns:
      A new Date or Instant
    • plusDays

      public java.lang.Object plusDays​(java.lang.Object dateOrInstant, long days)
      Adds days to a Date or Instant.
      Parameters:
      dateOrInstant - the basis Date or Instant
      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 a Date or Instant.
      Parameters:
      dateOrInstant - the basis Date or Instant
      weeks - the number of weeks to add
      Returns:
      A new Date or Instant
    • plusMonths

      public java.lang.Object plusMonths​(java.lang.Object dateOrInstant, long months)
      Adds months to a Date or Instant.
      Parameters:
      dateOrInstant - the basis Date or Instant
      months - the number of months to add
      Returns:
      A new Date or Instant
    • plusYears

      public java.lang.Object plusYears​(java.lang.Object dateOrInstant, long years)
      Adds years from an Date or Instant.
      Parameters:
      dateOrInstant - the basis Date or Instant
      years - the number of years to add
      Returns:
      A new Date or Instant
    • plusDuration

      public java.lang.Object plusDuration​(java.lang.Object dateOrInstant, java.lang.String iso8601Duration)
      Adds an ISO8601-encoded duration to a Date or Instant.
      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 basis Date or Instant
      iso8601Duration - the duration to be added to the instant
      Returns:
      A new Date or Instant
    • minusSeconds

      public java.lang.Object minusSeconds​(java.lang.Object dateOrInstant, long seconds)
      Subtracts seconds from an Date or Instant.
      Parameters:
      dateOrInstant - the basis Date or Instant
      seconds - the number of seconds to subtract
      Returns:
      A new Date or Instant
    • minusMinutes

      public java.lang.Object minusMinutes​(java.lang.Object dateOrInstant, long minutes)
      Subtracts minutes from an Date or Instant.
      Parameters:
      dateOrInstant - the basis Date or Instant
      minutes - the number of minutes to subtract
      Returns:
      A new Date or Instant
    • minusHours

      public java.lang.Object minusHours​(java.lang.Object dateOrInstant, long hours)
      Subtracts hours from an Date or Instant.
      Parameters:
      dateOrInstant - the basis Date or Instant
      hours - the number of hours to subtract
      Returns:
      A new Date or Instant
    • minusDays

      public java.lang.Object minusDays​(java.lang.Object dateOrInstant, long days)
      Subtracts hours from an instant.
      Parameters:
      dateOrInstant - the basis Date or Instant
      days - the number of days to subtract
      Returns:
      A new Date or Instant
    • minusWeeks

      public java.lang.Object minusWeeks​(java.lang.Object dateOrInstant, long weeks)
      Subtracts weeks to an Date or Instant.
      Parameters:
      dateOrInstant - the basis Date or Instant
      weeks - the number of weeks to subtract
      Returns:
      A new Date or Instant
    • minusMonths

      public java.lang.Object minusMonths​(java.lang.Object dateOrInstant, long months)
      Subtracts months from a Date or Instant.
      Parameters:
      dateOrInstant - the basis Date or Instant
      months - the number of months to subtract
      Returns:
      A new Date or Instant
    • minusYears

      public java.lang.Object minusYears​(java.lang.Object dateOrInstant, long years)
      Subtracts years to a Date or Instant.
      Parameters:
      dateOrInstant - the basis Date or Instant
      years - the number of years to subtract
      Returns:
      A new Date or Instant
    • minusDuration

      public java.lang.Object minusDuration​(java.lang.Object dateOrInstant, java.lang.String iso8601Duration)
      Subtracts an ISO8601-encoded duration from a Date or Instant. 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 basis Date or Instant
      iso8601Duration - the duration to be added
      Returns:
      A new Date or Instant
    • 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 another Date or Instant.
      Parameters:
      dateOrInstant - first Date or Instant to compare to
      otherDateOrInstant - Date or Instant to which to compare
      Returns:
      Whether or not the first Date or Instant is before the second Date or Instant
    • isAfter

      public boolean isAfter​(java.lang.Object dateOrInstant, java.lang.Object otherDateOrInstant)
      Checks if the Date or Instant is after another Date or Instant.
      Parameters:
      dateOrInstant - first Date or Instant to compare to
      otherDateOrInstant - Date or Instant to which to compare
      Returns:
      Whether or not the first Date or Instant is after the second Date or Instant
    • isBeforeTime

      public boolean isBeforeTime​(java.lang.Object dateOrInstant, java.lang.String timeZoneId, int hours, int minutes, int seconds)
      Checks if an Date or Instant is before a certain time in a given time zone.
      Parameters:
      dateOrInstant - Date or Instant to compare the time to
      timeZoneId - the time zone of the given instant
      hours - hour within the same day
      minutes - minutes within the hour
      seconds - seconds within the minute
      Returns:
      Whether or not the given Date or Instant 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 an Date or Instant is after a certain time in a given time zone.
      Parameters:
      dateOrInstant - Date or Instant to compare the time to
      timeZoneId - the time zone of the given instant
      hours - hour within the same day
      minutes - minutes within the hour
      seconds - seconds within the minute
      Returns:
      Whether or not the given Date or Instant 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 two Date or Instant.
      Parameters:
      firstDateOrInstant - the first Date or Instant
      secondDateOrInstant - the second Date or Instant
      Returns:
      Number of seconds between the two Date or Instant
    • getFieldFromDurationBetweenDates

      public long getFieldFromDurationBetweenDates​(java.lang.Object firstDateOrInstant, java.lang.Object secondDateOrInstant, java.lang.String chronoUnitString)
      Gets the duration between two Date or Instant 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 first Date or Instant
      secondDateOrInstant - the second Date or Instant
      chronoUnitString - chrono Unit to be extracted, e.g. 'Seconds' or 'Days'
      Returns:
      Duration between two Date or Instant 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 an Date or Instant 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 at
      timeZoneId - 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