Details
since | 1.3 |
---|---|
action-pack | Core |
author | JOSF-core team |
status | active |
Built-in functions to get the current date or time.
Functions are always written just like variables: ${myKeyword}
. Except that functions have parentheses at the end of the function name: ()
. These parentheses can hold parameters to add more functionality to the functions.
today()
Returns the current date. For formatting, review the Configuration section.
Parameter list
The today()
function accepts a couple of parameters to add or subtract values from todays date.
Given the current date is 24-05-2018.
Symbol | Description | Example | Result |
---|---|---|---|
y | add/subtract # years | today(+1y) | 24-05-2019 |
m | add/subtract # months | today(+1m) | 24-06-2018 |
w | add/subtract # weeks | today(+1w) | 31-05-2018 |
d | add/subtract # days | today(+1d) | 25-05-2018 |
A more complex, but valid use case would be: today(+1w-2d)
wich translates to today plus 1 week, minus 2 days. Off course today(+5d)
would also work just fine. Even today(+1y-40d+12w)
would return a valid date.
now()
Returns the current time. For formatting, review the Configuration section.
Parameter list
The now()
function accepts a couple of parameters to add or subtract values from this moment in time.
Given the current time is 15:05:38.
Symbol | Description | Example | Result |
---|---|---|---|
h | add/subtract # hours | now(+1h) | 16:05:38 |
m | add/subtract # minutes | now(+23m) | 16:28:38 |
s | add/subtract # secons | now(+12s) | 16:05:50 |
A more complex, but valid use case would be: now(+2h-50s)
wich translates to now plus 2 hours, minus 50 seconds.
Even now(+3h-40m+12s)
would return a valid time.
Example
Remember to wrap functions into the ${}
format!
Action name | Object | Data | Result |
---|---|---|---|
type | id=lst-ib | ${today()} | Todays date, formatted as configured |
type | id=lst-ib | ${now()} | Current time, formatted as configured |
verifyText | id=lst-ib | ${today(+2d)} | verifies wheter the text is equal to the day after tomorrow |
Configuration
The format of the date and time can be adjusted by editing the config.json
file, located in C:\Program Files\JOSF\src\main\conf\config.json
. In this file, (if not already present) two configuration properties can be added; FormatDate
& FormatTime
like so:
"FormatTime" : "kk:mm:ss",
"FormatDate" : "dd-MM-yyyy"
Formatting date & time
Formatting date and time uses a specific pattern. In the example above, the FormatDate dd-MM-yyyy
formats a date as 25-10-2018. For a month-day-year format, we can use MM-dd-yyyy
. If we'd want to use slashes (/
), instead of dashes(-
), we can set a format as dd/MM/yyyy
.
For time, the same rules apply. The above example gives us a time (24 hours) format of hour:minute:second, or 22:01:20.
All supported formatting patterns can be reviewed in this table.
Symbol | Meaning | Presentation | Examples |
---|---|---|---|
G | era | text | AD; Anno Domini; A |
u | year | year | 2004; 04 |
y | year-of-era | year | 2004; 04 |
D | day-of-year | number | 189 |
M/L | month-of-year | number/text | 7; 07; Jul; July; J |
d | day-of-month | number | 10 |
Q/q | quarter-of-year | number/text | 3; 03; Q3; 3rd quarter |
Y | week-based-year | year | 1996; 96 |
w | week-of-week-based-year | number | 27 |
W | week-of-month | number | 4 |
E | day-of-week | text | Tue; Tuesday; T |
e/c | localized day-of-week | number/text | 2; 02; Tue; Tuesday; T |
F | week-of-month | number | 3 |
a | am-pm-of-day | text | PM |
h | clock-hour-of-am-pm (1-12) | number | 12 |
K | hour-of-am-pm (0-11) | number | 0 |
k | clock-hour-of-am-pm (1-24) | number | 0 |
H | hour-of-day (0-23) | number | 0 |
m | minute-of-hour | number | 30 |
s | second-of-minute | number | 55 |
S | fraction-of-second | fraction | 978 |
A | milli-of-day | number | 1234 |
n | nano-of-second | number | 987654321 |
N | nano-of-day | number | 1234000000 |
V | time-zone ID | zone-id | America/Los_Angeles; Z; -08:30 |
z | time-zone name | zone-name | Pacific Standard Time; PST |
O | localized zone-offset | offset-O | GMT+8; GMT+08:00; UTC-08:00; |
X | zone-offset 'Z' for zero | offset-X | Z; -08; -0830; -08:30; -083015; -08:30:15; |
x | zone-offset | offset-x | +0000; -08; -0830; -08:30; -083015; -08:30:15; |
Z | zone-offset | offset-Z | +0000; -0800; -08:00; |
p | pad next | pad modifier | 1 |
' | escape for text | delimiter | |
'' | single quote | literal | ' |
[ | optional section start | ||
] | optional section end | ||
# | reserved for future use | ||
{ | reserved for future use | ||
} | reserved for future use |
For more information about formatting, please visit: https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html