Class FlowableExpressionTimeUtils
- java.lang.Object
-
- com.flowable.platform.expressions.FlowableExpressionTimeUtils
-
public class FlowableExpressionTimeUtils extends 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(flwTimeUtils.now(), 10)}
-
-
Constructor Summary
Constructors Constructor Description FlowableExpressionTimeUtils()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
areEqual(Object firstValue, Object secondValue)
Checks if the first value is equal to the second value.Date
asDate(Object value)
Converts a value to a date.Instant
asInstant(Object value)
Converts a value to an Instant.Instant
asInstant(Object value, String zoneId)
Converts a value to an Instant in the given zone.protected Instant
asInstant(Object value, ZoneId zoneId)
LocalDate
asLocalDate(Object value)
Converts a value to a LocalDate.LocalDate
asLocalDate(Object value, String zoneId)
Converts a value to a LocalDate in the given zone.protected LocalDate
asLocalDate(Object value, ZoneId zoneId)
LocalDateTime
asLocalDateTime(Object value)
Converts a value to a LocalDateTime.LocalDateTime
asLocalDateTime(Object value, String zoneId)
Converts a value to a LocalDateTime in the given zone.protected LocalDateTime
asLocalDateTime(Object value, ZoneId zoneId)
Object
atTime(Object value, int hours, int minutes, int seconds)
Sets the time of the value to the specified hours, minutes and seconds.Object
atTimeWithTimeZone(Object value, int hours, int minutes, int seconds, String timezoneId)
Sets the time of the value to the specified hours, minutes and seconds in the given timezone.Object
atTimeZone(Object dateOrInstant, String timeZoneId)
Returns an instant at a specified time zone.Instant
currentDate()
Returns the current date at 00:00 AM UTC.LocalDate
currentLocalDate()
LocalDateTime
currentLocalDateTime()
Date
dateFromTimestamp(long timestamp)
Returns a date from the number of seconds that have passed since the first of January 1970 (Unix Timestamp).long
daysBetween(Object firstValue, Object secondValue)
Get the number of days between two values.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.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.List<String>
getAvailableTimeZoneIds()
Receives a list of all available timeZoneIds maintained as specified by the IANA.protected long
getDurationBetween(Object firstValue, Object secondValue, ChronoUnit chronoUnit)
int
getField(Object value, String chronoFieldString)
Obtains a "slice of time" by specifying aChronoField
asString
.long
getFieldFromDurationBetweenDates(Object firstDateOrInstant, Object secondDateOrInstant, String chronoUnitString)
Gets the duration between two values.long
getTimeZoneOffset(Object value, String timeZoneId)
Calculates the number of seconds a specific point in time at a specified time zone is set off from UTC.long
hoursBetween(Object firstValue, Object secondValue)
Get the number of hours between two values.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(Object firstValue, Object secondValue)
Checks if the first value is after the second value.boolean
isAfterOrEqual(Object firstValue, Object secondValue)
Checks if the first value is after or equal to the second value.boolean
isAfterTime(Object value, String timeZoneId, int hours, int minutes, int seconds)
Checks if the givenvalue
is after a certain time in a given time zone.boolean
isBefore(Object firstValue, Object secondValue)
Checks if the first value is before the second value.boolean
isBeforeOrEqual(Object firstValue, Object secondValue)
Checks if the first value is before or equals to the second value.boolean
isBeforeTime(Object value, String timeZoneId, int hours, int minutes, int seconds)
Checks if the givenvalue
is before a certain time in a given time zone.boolean
isWeekend(Object value)
Determines whether the current day is a weekend.Object
minusDays(Object value, long days)
Subtracts days from the defined value.Object
minusDuration(Object value, String iso8601Duration)
Subtracts an ISO8601-encoded duration to the value.Object
minusHours(Object value, long hours)
Subtracts hours from the defined value.Object
minusMinutes(Object value, long minutes)
Subtracts minutes from the defined value.Object
minusMonths(Object value, long months)
Subtracts months from the defined value.Object
minusSeconds(Object value, long seconds)
Subtracts seconds from the defined value.Object
minusWeeks(Object value, long weeks)
Subtracts weeks from the defined value.Object
minusYears(Object value, long years)
Subtracts years from the defined value.long
minutesBetween(Object firstValue, Object secondValue)
Get the number of minutes between two values.long
monthsBetween(Object firstValue, Object secondValue)
Get the number of months between two values.Instant
now()
Returns the current date and time in UTC.Instant
parseInstant(Object value, String pattern)
Parse the object in to an Instant Supported inputs are: String Json TextNodenull
Instant
parseInstant(String instantIsoString)
Parse an ISO 8601 String to Instant.LocalDate
parseLocalDate(Object value, String pattern)
Parse the object in to a LocalDate Supported inputs are: String Json TextNodenull
LocalDateTime
parseLocalDateTime(Object value, String pattern)
Parse the object in to a LocalDateTime Supported inputs are: String Json TextNodenull
Object
plusDays(Object value, long days)
Adds days to the defined value.Object
plusDuration(Object value, String iso8601Duration)
Adds an ISO8601-encoded duration to the value.Object
plusHours(Object value, long hours)
Adds hours to the defined value.Object
plusMinutes(Object value, long minutes)
Adds minutes to the defined value.Object
plusMonths(Object value, long months)
Adds months to the defined value.Object
plusSeconds(Object value, long seconds)
Adds seconds to the defined value.Object
plusWeeks(Object value, long weeks)
Adds weeks to the defined value.Object
plusYears(Object value, long years)
Adds years to the defined value.long
secondsBetween(Object firstValue, Object secondValue)
Get the number of seconds between two values.long
secondsBetweenDates(Object firstValue, Object secondValue)
Deprecated.usesecondsBetween(Object, Object)
insteadlong
secondsOfDuration(String iso8601Duration)
Gets the number of seconds in a ISO duration string, e.g.long
weeksBetween(Object firstValue, Object secondValue)
Get the number of weeks between two values.long
yearsBetween(Object firstValue, Object secondValue)
Get the number of years between two values.
-
-
-
Method Detail
-
parseInstant
public Instant parseInstant(String instantIsoString)
Parse an ISO 8601 String to Instant.- Parameters:
instantIsoString
- the ISO 8601 String, nevernull
- Returns:
- the Instant representing the ISO 8601 String
-
parseInstant
public Instant parseInstant(Object value, String pattern)
Parse the object in to an Instant Supported inputs are:- String
- Json TextNode
null
- Parameters:
value
- the object that should be parsedpattern
- the pattern that should be used for the parsing- Returns:
- the Instant representing the object, or
null
if the object was null
-
parseLocalDate
public LocalDate parseLocalDate(Object value, String pattern)
Parse the object in to a LocalDate Supported inputs are:- String
- Json TextNode
null
- Parameters:
value
- the object that should be parsedpattern
- the pattern that should be used for parsing- Returns:
- the LocalDate representing the object, or
null
if the object was null
-
parseLocalDateTime
public LocalDateTime parseLocalDateTime(Object value, String pattern)
Parse the object in to a LocalDateTime Supported inputs are:- String
- Json TextNode
null
- Parameters:
value
- the object that should be parsedpattern
- the pattern that should be used for parsing- Returns:
- the LocalDateTime representing the object, or
null
if the object was null
-
asInstant
public Instant asInstant(Object value)
Converts a value to an Instant. Supported inputs are:- Date
- Instant - it will return itself
- LocalDate - It will use the start of day in the UTC zone
- LocalDateTime - It will use the UTC zone
- ISO 8601 String - also supports LocalDate and LocalDateTime values
null
- Parameters:
value
- the value to be converted- Returns:
- An
Instant
based on the provided value.
-
asInstant
public Instant asInstant(Object value, String zoneId)
Converts a value to an Instant in the given zone. Supported inputs are:- Date
- Instant - it will return itself
- LocalDate - It will use the start of day in the requested zone
- LocalDateTime - It will use the requested zone
- ISO 8601 String - also supports LocalDate and LocalDateTime values
null
zoneId
is only used when the value is a LocalDate, LocalDateTime or a String representing a LocalDate or LocalDateTime- Parameters:
value
- the value to be convertedzoneId
- the zone that should be used for converting a LocalDate or LocalDateTime- Returns:
- An
Instant
based on the provided value.
-
asLocalDate
public LocalDate asLocalDate(Object value)
Converts a value to a LocalDate. Supported inputs are:- Parameters:
value
- the value to be converted- Returns:
- A
LocalDate
based on the provided value.
-
asLocalDate
public LocalDate asLocalDate(Object value, String zoneId)
Converts a value to a LocalDate in the given zone. Supported inputs are:- Date - It will use the
LocalDate
in the provided zone - Instant - It will use the
LocalDate
in the provided zone - LocalDate
- LocalDateTime
- ISO 8601 String - also supports Instant, LocalDate and LocalDateTime values
null
zoneId
is only used when the value is an Instant, Date or a String representing an Instant- Parameters:
value
- the value to be convertedzoneId
- the zone that should be used for converting a LocalDate or LocalDateTime- Returns:
- A
LocalDate
based on the provided value.
- Date - It will use the
-
asLocalDateTime
public LocalDateTime asLocalDateTime(Object value)
Converts a value to a LocalDateTime. Supported inputs are:- Date - It will use the
LocalDateTime
in the UTC zone - Instant - It will use the
LocalDateTime
in the UTC zone - LocalDate - It will use start of day
- LocalDateTime
- ISO 8601 String - also supports Instant, LocalDate and LocalDateTime values
null
- Parameters:
value
- the value to be converted- Returns:
- A
LocalDateTime
based on the provided value.
- Date - It will use the
-
asLocalDateTime
public LocalDateTime asLocalDateTime(Object value, String zoneId)
Converts a value to a LocalDateTime in the given zone. Supported inputs are:- Date - It will use the
LocalDateTime
in provided zone - Instant - It will use the
LocalDateTime
in provided zone - LocalDate - It will use start of date
- LocalDateTime
- ISO 8601 String - also supports Instant, LocalDate and LocalDateTime values
null
zoneId
is only used when the value is an Instant, Date or a String representing an Instant- Parameters:
value
- the value to be convertedzoneId
- the zone that should be used for converting a LocalDate or LocalDateTime- Returns:
- A
LocalDateTime
based on the provided value.
- Date - It will use the
-
asLocalDateTime
protected LocalDateTime asLocalDateTime(Object value, ZoneId zoneId)
-
asDate
public Date asDate(Object value)
Converts a value to a date. This is useful in places where the old Java Date API is still used. Supported inputs are:- Instant
- LocalDate - It will use the start of day in the UTC zone
- LocalDateTime - It will use the UTC zone
- ISO 8601 String - also supports LocalDate and LocalDateTime values
null
- Parameters:
value
- the value to be converted- Returns:
- A
Date
based on the provided value.
-
atTime
public Object atTime(Object value, int hours, int minutes, int seconds)
Sets the time of the value to the specified hours, minutes and seconds. The ZoneOffset is UTC. The value can be:- Date
- Instant
- LocalDateTime
- ISO 8601 String - It will return an Instant or LocalDateTime
- Parameters:
value
- the basishours
- the hours to be setminutes
- the minutes to be setseconds
- the seconds to be set- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
atTimeWithTimeZone
public Object atTimeWithTimeZone(Object value, int hours, int minutes, int seconds, String timezoneId)
Sets the time of the value to the specified hours, minutes and seconds in the given timezone. The value can be:- Date
- Instant
- LocalDateTime
- ISO 8601 String - It will return an Instant or LocalDateTime
- Parameters:
value
- the basishours
- the hours to be setminutes
- the minutes to be setseconds
- the seconds to be settimezoneId
- the time zone- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
atTimeZone
public Object atTimeZone(Object dateOrInstant, 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(flwTimeUtils.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!
-
getAvailableTimeZoneIds
public List<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(Object value, 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(flwTimeUtils.now(), "DAY_OF_WEEK")}
to obtain the current day of the week
Example:#{flwTimeUtils.getField(flwTimeUtils.now(), "SECOND_OF_MINUTE")}
to obtain the seconds in the current minute
Example:#{flwTimeUtils.getField(flwTimeUtils.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. Supports input for:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
- Parameters:
value
- from which te time should be extractedchronoFieldString
- the name of a chrono field, seeChronoField
- Returns:
- An
int
representing the desiredChronoField
of the instance in UTC.
-
isWeekend
public boolean isWeekend(Object value)
Determines whether the current day is a weekend. It can check the following types:- Date
- Instant - The check is done in the UTC zone
- LocalDate
- LocalDateTime
- ISO 8601 String
-
fullDateTimeInstant
public 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 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 Object plusSeconds(Object value, long seconds)
Adds seconds to the defined value. Supports the following input:- Date
- Instant
- LocalDateTime
- ISO 8601 String - It will return an Instant or LocalDateTime
- Parameters:
value
- the basisseconds
- the number of seconds to add- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
plusMinutes
public Object plusMinutes(Object value, long minutes)
Adds minutes to the defined value. Supports the following input:- Date
- Instant
- LocalDateTime
- ISO 8601 String - It will return an Instant or LocalDateTime
- Parameters:
value
- the basisminutes
- the number of minutes to add- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
plusHours
public Object plusHours(Object value, long hours)
Adds hours to the defined value. Supports the following input:- Date
- Instant
- LocalDateTime
- ISO 8601 String - It will return an Instant or LocalDateTime
- Parameters:
value
- the basishours
- the number of hours to add- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
plusDays
public Object plusDays(Object value, long days)
Adds days to the defined value. Supports the following input:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String - It will return an Instant, LocalDate or LocalDateTime
- Parameters:
value
- the basisdays
- the number of days to add- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
plusWeeks
public Object plusWeeks(Object value, long weeks)
Adds weeks to the defined value. Supports the following input:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String - It will return an Instant, LocalDate or LocalDateTime
- Parameters:
value
- the basisweeks
- the number of weeks to add- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
plusMonths
public Object plusMonths(Object value, long months)
Adds months to the defined value. Supports the following input:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String - It will return an Instant, LocalDate or LocalDateTime
- Parameters:
value
- the basismonths
- the number of months to add- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
plusYears
public Object plusYears(Object value, long years)
Adds years to the defined value. Supports the following input:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String - It will return an Instant, LocalDate or LocalDateTime
- Parameters:
value
- the basisyears
- the number of years to add- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
plusDuration
public Object plusDuration(Object value, String iso8601Duration)
Adds an ISO8601-encoded duration to the value.Example:
#{flwTimeUtils.plusDuration(flwTimeUtils.now(), 'P1Y')}
adds a yearExample:
#{flwTimeUtils.plusDuration(flwTimeUtils.now(), 'P14D')}
adds 14 daysExample:
#{flwTimeUtils.plusDuration(flwTimeUtils.now(), 'PT30M10S')}
adds 30 minutes and ten secondsSupports the following input:
- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String - It will return an Instant, LocalDate or LocalDateTime
- Parameters:
value
- the basisiso8601Duration
- the duration to be added to the value- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
minusSeconds
public Object minusSeconds(Object value, long seconds)
Subtracts seconds from the defined value. Supports the following input:- Date
- Instant
- LocalDateTime
- ISO 8601 String - It will return an Instant or LocalDateTime
- Parameters:
value
- the basisseconds
- the number of seconds to subtract- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
minusMinutes
public Object minusMinutes(Object value, long minutes)
Subtracts minutes from the defined value. Supports the following input:- Date
- Instant
- LocalDateTime
- ISO 8601 String - It will return an Instant or LocalDateTime
- Parameters:
value
- the basisminutes
- the number of minutes to subtract- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
minusHours
public Object minusHours(Object value, long hours)
Subtracts hours from the defined value. Supports the following input:- Date
- Instant
- LocalDateTime
- ISO 8601 String - It will return an Instant or LocalDateTime
- Parameters:
value
- the basishours
- the number of hours to subtract- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
minusDays
public Object minusDays(Object value, long days)
Subtracts days from the defined value. Supports the following input:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String - It will return an Instant, LocalDate or LocalDateTime
- Parameters:
value
- the basisdays
- the number of days to subtract- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
minusWeeks
public Object minusWeeks(Object value, long weeks)
Subtracts weeks from the defined value. Supports the following input:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String - It will return an Instant, LocalDate or LocalDateTime
- Parameters:
value
- the basisweeks
- the number of weeks to subtract- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
minusMonths
public Object minusMonths(Object value, long months)
Subtracts months from the defined value. Supports the following input:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String - It will return an Instant, LocalDate or LocalDateTime
- Parameters:
value
- the basismonths
- the number of months to subtract- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
minusYears
public Object minusYears(Object value, long years)
Subtracts years from the defined value. Supports the following input:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String - It will return an Instant, LocalDate or LocalDateTime
- Parameters:
value
- the basisyears
- the number of years to subtract- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
minusDuration
public Object minusDuration(Object value, String iso8601Duration)
Subtracts an ISO8601-encoded duration to the value.Example:
#{flwTimeUtils.minusDuration(flwTimeUtils.now(), 'P1Y')}
subtracts a yearExample:
#{flwTimeUtils.minusDuration(flwTimeUtils.now(), 'P14D')}
subtracts 14 daysExample:
#{flwTimeUtils.minusDuration(flwTimeUtils.now(), 'PT30M10S')}
subtracts 30 minutes and ten secondsSupports the following input:
- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String - It will return an Instant, LocalDate or LocalDateTime
- Parameters:
value
- the basisiso8601Duration
- the duration to be subtracted from the value- Returns:
- A new basis type, with the same type as the
value
(unless it is a string)
-
secondsOfDuration
public long secondsOfDuration(String iso8601Duration)
Gets the number of seconds in a ISO duration string, e.g. PT60M returns 3600.- Parameters:
iso8601Duration
- the ISO 8601 duration string, nevernull
- Returns:
- Number of seconds in the given duration
-
currentDate
public 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(Object firstValue, Object secondValue)
Checks if the first value is before the second value. The check is done by converting the second value to the same type as the first one. It allows comparing:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
- Parameters:
firstValue
- first value to comparesecondValue
- second value to which to compare to- Returns:
true
if the first value is before the second one,false otherwise
-
isBeforeOrEqual
public boolean isBeforeOrEqual(Object firstValue, Object secondValue)
Checks if the first value is before or equals to the second value. The check is done by converting the second value to the same type as the first one. It allows comparing:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
- Parameters:
firstValue
- first value to comparesecondValue
- second value to which to compare to- Returns:
true
if the first value is before the second one,false otherwise
-
isAfter
public boolean isAfter(Object firstValue, Object secondValue)
Checks if the first value is after the second value. The check is done by converting the second value to the same type as the first one. It allows comparing:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
- Parameters:
firstValue
- first value to comparesecondValue
- second value to which to compare to- Returns:
true
if the first value is after the second one,false otherwise
-
isAfterOrEqual
public boolean isAfterOrEqual(Object firstValue, Object secondValue)
Checks if the first value is after or equal to the second value. The check is done by converting both values to an Instant and then comparing them. It allows comparing:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
- Parameters:
firstValue
- first value to comparesecondValue
- second value to which to compare to- Returns:
true
if the first value is after the second one,false otherwise
-
areEqual
public boolean areEqual(Object firstValue, Object secondValue)
Checks if the first value is equal to the second value. The check is done by converting the second value to the same type as the first one. It allows comparing:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
- Parameters:
firstValue
- first value to comparesecondValue
- second value to which to compare to- Returns:
true
if the first value is equal to the second one,false otherwise
-
isBeforeTime
public boolean isBeforeTime(Object value, String timeZoneId, int hours, int minutes, int seconds)
Checks if the givenvalue
is before a certain time in a given time zone. The value can be- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
The conversion is done by converting the
value
into an instant in the given time zone.- Parameters:
value
- to compare the time totimeZoneId
- the time zone in which to do the comparisonhours
- hour within the same dayminutes
- minutes within the hourseconds
- seconds within the minute- Returns:
true
if the value is before the given time,false otherwise
-
isAfterTime
public boolean isAfterTime(Object value, String timeZoneId, int hours, int minutes, int seconds)
Checks if the givenvalue
is after a certain time in a given time zone. The value can be- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
The conversion is done by converting the
value
into an instant in the given time zone.- Parameters:
value
- to compare the time totimeZoneId
- the time zone in which to do the comparisonhours
- hour within the same dayminutes
- minutes within the hourseconds
- seconds within the minute- Returns:
true
if the value is after the given time,false otherwise
-
secondsBetweenDates
@Deprecated public long secondsBetweenDates(Object firstValue, Object secondValue)
Deprecated.usesecondsBetween(Object, Object)
insteadReturns the number of seconds between two values. Each value will be converted to an Instant in the UTC timezone before doing the comparison. The values can be- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
- Parameters:
firstValue
- the first valuesecondValue
- the second value- Returns:
- Number of seconds between the two values
-
getFieldFromDurationBetweenDates
public long getFieldFromDurationBetweenDates(Object firstDateOrInstant, Object secondDateOrInstant, String chronoUnitString)
Gets the duration between two values. Supports the following input:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
- Parameters:
firstDateOrInstant
- the firstDate
orInstant
secondDateOrInstant
- the secondDate
orInstant
chronoUnitString
- chrono Unit to be extracted, e.g. 'Seconds' or 'Days', seeChronoUnit
for available values- Returns:
- the duration between the two values in the specific unit
-
secondsBetween
public long secondsBetween(Object firstValue, Object secondValue)
Get the number of seconds between two values. Supports the following input:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
- Parameters:
firstValue
- the first valuesecondValue
- the second value- Returns:
- the number of seconds between the two values
-
minutesBetween
public long minutesBetween(Object firstValue, Object secondValue)
Get the number of minutes between two values. Supports the following input:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
- Parameters:
firstValue
- the first valuesecondValue
- the second value- Returns:
- the number of minutes between the two values
-
hoursBetween
public long hoursBetween(Object firstValue, Object secondValue)
Get the number of hours between two values. Supports the following input:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
- Parameters:
firstValue
- the first valuesecondValue
- the second value- Returns:
- the number of hours between the two values
-
daysBetween
public long daysBetween(Object firstValue, Object secondValue)
Get the number of days between two values. Supports the following input:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
- Parameters:
firstValue
- the first valuesecondValue
- the second value- Returns:
- the number of days between the two values
-
weeksBetween
public long weeksBetween(Object firstValue, Object secondValue)
Get the number of weeks between two values. Supports the following input:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
- Parameters:
firstValue
- the first valuesecondValue
- the second value- Returns:
- the number of weeks between the two values
-
monthsBetween
public long monthsBetween(Object firstValue, Object secondValue)
Get the number of months between two values. Supports the following input:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
- Parameters:
firstValue
- the first valuesecondValue
- the second value- Returns:
- the number of months between the two values
-
yearsBetween
public long yearsBetween(Object firstValue, Object secondValue)
Get the number of years between two values. Supports the following input:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
- Parameters:
firstValue
- the first valuesecondValue
- the second value- Returns:
- the number of years between the two values
-
getDurationBetween
protected long getDurationBetween(Object firstValue, Object secondValue, ChronoUnit chronoUnit)
-
getTimeZoneOffset
public long getTimeZoneOffset(Object value, String timeZoneId)
Calculates the number of seconds a specific point in time at a specified time zone is set off from UTC. The value can be:- Date
- Instant
- LocalDate
- LocalDateTime
- ISO 8601 String
Example:
#{flwTimeUtils.getTimZoneOffset(flwTimeUtils.now(), "Pacific/Honolulu)}
calculates the number of seconds between Honolulu and UTC time- Parameters:
value
- the date you want to check the offset attimeZoneId
- the time zone- Returns:
- The offset in seconds
-
instantFromTimestamp
public 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 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 Instant now()
Returns the current date and time in UTC.- Returns:
- Current date and time
-
currentLocalDate
public LocalDate currentLocalDate()
-
currentLocalDateTime
public LocalDateTime currentLocalDateTime()
-
-