Date/Time Plugin
The plugin provides functionality to generate, modify and validate date/time.
Installation
implementation(group: 'org.vividus', name: 'vividus-plugin-datetime', version: '0.3.0')
Properties
Optional
location.zone-id
- Defines time zone which will be used. The default is set to a system default timezone. Time zone format
Expressions
The expression parameters marked with bold are mandatory. |
generateDate
Generates the date using current date as a baseline.
#{generateDate($period, $outputFormat)}
-
period
- the period in ISO-8601 format -
outputFormat
- the output format based on the date/time format
Let’s imagine the current date is 2020-11-23
and the time is 00:10:01
. Here is a set of examples with the results and comments.
Expression | Result | Comment |
---|---|---|
|
2020-11-23 |
Current date. |
|
2020-11-24T02:10:01 |
Current date +1 day and +2 hours |
|
2020-11-23 |
Current date -1 day |
|
2020-12-23 |
Current date + 1 month |
|
2020-11-23T00:00:01 |
Current date time -10 mins |
|
2020-11 |
Current date with the custom output format |
|
11/23/2020 |
Current date with a custom format |
|
20-11-24 |
Current date +1 day with the custom output format |
|
2020-11-23’T'00:10:01+0300 |
Current date with the custom output format including time zone offset |
formatDate
Formats the input date to another format. Additionally, time zone can be changed in the output result.
#{formatDate($inputDate, $outputFormat, $outputTimeZone)}
-
$inputDate
- the date to be formatted, it should be presented in the ISO-8601 format -
$outputFormat
- the outut format based on the date/time format -
$outputTimeZone
- the time zone for the output result
Expression | Result |
---|---|
|
2017-01-13T09:00:42.862 |
|
2017-01-13T09:00:42.862 |
|
Throw exception |
|
2017-01-13T09:00:42 |
|
2017-01-13T09:00:42+0000 |
|
2017-01-13T09:00:42-05:00 |
|
2017-01-13 |
|
2017-01-13T04:00:42.862-0500 |
|
2017-01-13T09:00:42.862+0000 |
|
2017-01-13T04:00:42.862-0500 |
|
Error: invalid input data |
|
Error: invalid output format |
|
Error: invalid output timezone |
formatDateTo
Formats the input date to the desired format. The format of the input date should be provided in the second parameter.
#{formatDateTo($inputDate, $inputFormat, $outputFormat)}
-
$inputDate
- the date to be formatted, it can be in any format but this format should be described in the second parameter -
$inputFormat
- the input date format based on the date/time format -
$outputFormat
- the output date format based on the date/time format
Since parameters of the expression comma-separated, meaningful commas (like, parts of the date format pattern) should be escaped using \ .
|
Expression | Result |
---|---|
|
Fri, 31 Mar 2017 07:20:43 GMT |
|
2017-03-31T07:20:43 |
shiftDate
Shifts the given input date for a given period in any direction (+/-).
#{shiftDate($inputDate, $inputFormat, $period)}
-
$inputDate
- the date to be shifted, it can be in any format but this format should be described in the second parameter -
$inputFormat
- the input date format based on the date/time format -
$period
- the period by which the date will be shifted, it should be written in ISO-8601
Since parameters of the expression comma-separated, meaningful commas (like, parts of the date format pattern) should be escaped using \ .
|
Expression | Result |
---|---|
|
2018-03-19 01:40:00 |
|
Fri, 10 May 2019 09:20:43 GMT |
|
"Fri, 10 May, 2019, 09:20:43 GMT" |
diffDate
Calculates the difference between two dates with given formats and returns result as ISO-8601 period.
#{diffDate($inputDate1, $inputDate1Format, $inputDate2, $inputDate2Format)}
-
$inputDate1
- the first input date, it can be in any format but this format should be described in the second parameter -
$inputDate1Format
- the first input date format based on the date/time format -
$inputDate2
- the second input date, it can be in any format but this format should be described in the second parameter -
$inputDate2Format
- the second input date format based on the date/time format
Since parameters of the expression comma-separated, meaningful commas (like, parts of the date format pattern) should be escaped using \ .
|
Expression | Result |
---|---|
|
PT0S |
|
PT0S |
|
PT8774591H59M20S |
toEpochSecond
Converts the input date to the unix epoch time (the number of seconds from the epoch of 1970-01-01T00:00:00Z).
#{toEpochSecond($inputDate)}
-
$inputDate
- the date to be formatted, it should be presented in the ISO-8601 format
Expression | Result |
---|---|
|
734918400 |
|
1607692385 |
Steps
Dates comparison
Parameters
-
$date
- the date in the ISO-8601 format -
$comparisonRule
- Comparison Rule -
$seconds
- the quantity of seconds between current and the date.
Dates comparison with custom date format
Info
Validates the difference between the current date and the date under test in seconds using custom date format.
Wording
Then the date '$date' in the format '$format' is $comparisonRule current for $seconds seconds
Parameters
-
$date
- the date to validate -
$format
- the date in the date/time format -
$comparisonRule
- Comparison Rule -
$seconds
- the quantity of seconds between current and the date