public class FlowableExpressionTimeUtils extends Object
Constructor and Description |
---|
FlowableExpressionTimeUtils() |
Modifier and Type | Method and Description |
---|---|
Date |
asDate(Instant instant)
Converts an instant to a date.
|
Object |
atTime(Object dateOrInstant,
int hours,
int minutes,
int seconds)
Sets the time of an instant to the specified hours, minutes and seconds.
|
Object |
atTimeWithTimeZone(Object dateOrInstant,
int hours,
int minutes,
int seconds,
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.
|
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.
|
Date |
dateFromTimestamp(long timestamp)
Returns a date from the number of seconds that have passed since the first of January 1970 (Unix Timestamp).
|
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. |
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. |
List<String> |
getAvailableTimeZoneIds()
Receives a list of all available timeZoneIds maintained as specified by the IANA.
|
int |
getField(Object dateOrInstant,
String chronoFieldString)
Obtains a "slice of time" by specifying a
ChronoField as String . |
long |
getFieldFromDurationBetweenDates(Object firstDateOrInstant,
Object secondDateOrInstant,
String chronoUnitString)
|
long |
getTimeZoneOffset(Object dateOrInstant,
String timeZoneId)
Calculates the number of seconds a specific point in time at a specified time zone is set off from UTC.
|
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 dateOrInstant,
Object otherDateOrInstant)
|
boolean |
isAfterTime(Object dateOrInstant,
String timeZoneId,
int hours,
int minutes,
int seconds)
|
boolean |
isBefore(Object dateOrInstant,
Object otherDateOrInstant)
|
boolean |
isBeforeTime(Object dateOrInstant,
String timeZoneId,
int hours,
int minutes,
int seconds)
|
boolean |
isWeekend(Object dateOrInstant)
Determines whether the current day is a weekend.
|
Object |
minusDays(Object dateOrInstant,
long days)
Subtracts hours from an instant.
|
Object |
minusDuration(Object dateOrInstant,
String iso8601Duration)
|
Object |
minusHours(Object dateOrInstant,
long hours)
|
Object |
minusMinutes(Object dateOrInstant,
long minutes)
|
Object |
minusMonths(Object dateOrInstant,
long months)
|
Object |
minusSeconds(Object dateOrInstant,
long seconds)
|
Object |
minusWeeks(Object dateOrInstant,
long weeks)
|
Object |
minusYears(Object dateOrInstant,
long years)
|
Instant |
now()
Returns the current date and time in UTC.
|
Instant |
parseInstant(String instantIsoString) |
Instant |
parseInstant(String instantString,
String pattern) |
Object |
plusDays(Object dateOrInstant,
long days)
|
Object |
plusDuration(Object dateOrInstant,
String iso8601Duration)
|
Object |
plusHours(Object dateOrInstant,
long hours)
|
Object |
plusMinutes(Object dateOrInstant,
long minutes)
Adds minutes to an instant.
|
Object |
plusMonths(Object dateOrInstant,
long months)
|
Object |
plusSeconds(Object dateOrInstant,
long seconds)
|
Object |
plusWeeks(Object dateOrInstant,
long weeks)
|
Object |
plusYears(Object dateOrInstant,
long years)
|
long |
secondsBetweenDates(Object firstDateOrInstant,
Object secondDateOrInstant)
|
long |
secondsOfDuration(String iso8601Duration)
Gets the number of seconds in a ISO duration string, e.g.
|
public Date asDate(Instant instant)
instant
- the instant to be convertedDate
based on the provided instant.public Object atTime(Object dateOrInstant, int hours, int minutes, int seconds)
public Object atTimeWithTimeZone(Object dateOrInstant, int hours, int minutes, int seconds, String timezoneId)
public Object atTimeZone(Object dateOrInstant, String timeZoneId)
#{flwTimeUtils.atTimeZone(now(), 'Europe/Zurich')}
will return the current time in Zurich getAvailableTimeZoneIds()
public List<String> getAvailableTimeZoneIds()
atTimeZone(Object, String)
public int getField(Object dateOrInstant, String chronoFieldString)
ChronoField
as String
. #{flwTimeUtils.getField(now(), "DAY_OF_WEEK")}
to obtain the current day of the week #{flwTimeUtils.getField(now(), "SECOND_OF_MINUTE")}
to obtain the seconds in the current minute #{flwTimeUtils.getField(now(), "AlignedWeekOfYear")}
to obtain the calendar week. This example uses the display name of the Chrono Field. dateOrInstant
- base Date
or Instant
chronoFieldString
- the name of a chrono field, see ChronoField
int
representing the desired ChronoField
of the instance in UTC.public boolean isWeekend(Object dateOrInstant)
public Instant fullDateTimeInstant(int year, int month, int day, int hour, int minute, int second)
Instant
based on a given year, month, day, hour, minute and second.year
- the year to usemonth
- the month to useday
- the day to usehour
- the hour to useminute
- the minute to usesecond
- the second to useInstant
public Date fullDateTimeDate(int year, int month, int day, int hour, int minute, int second)
Date
based on a given year, month, day, hour, minute and second.year
- the year to usemonth
- the month to useday
- the day to usehour
- the hour to useminute
- the minute to usesecond
- the second to useDate
public Object plusMinutes(Object dateOrInstant, long minutes)
public long secondsOfDuration(String iso8601Duration)
iso8601Duration
- public Instant currentDate()
Instant
of the current date at 00:00 AM UTC.public boolean isBeforeTime(Object dateOrInstant, String timeZoneId, int hours, int minutes, int seconds)
dateOrInstant
- Date
or Instant
to compare the time totimeZoneId
- the time zone of the given instanthours
- hour within the same dayminutes
- minutes within the hourseconds
- seconds within the minuteDate
or Instant
is before the given time in a certain time zonepublic boolean isAfterTime(Object dateOrInstant, String timeZoneId, int hours, int minutes, int seconds)
dateOrInstant
- Date
or Instant
to compare the time totimeZoneId
- the time zone of the given instanthours
- hour within the same dayminutes
- minutes within the hourseconds
- seconds within the minuteDate
or Instant
is after the given time in a certain time zonepublic long secondsBetweenDates(Object firstDateOrInstant, Object secondDateOrInstant)
public long getFieldFromDurationBetweenDates(Object firstDateOrInstant, Object secondDateOrInstant, String chronoUnitString)
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.public long getTimeZoneOffset(Object dateOrInstant, String timeZoneId)
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.dateOrInstant
- the date you want to check the offset attimeZoneId
- the time zonepublic Instant instantFromTimestamp(long timestamp)
timestamp
- public Date dateFromTimestamp(long timestamp)
timestamp
- Date
at the specified time stamp.public Instant now()