Hi all…I was wondering if there are any facilities...
# help
d
Hi all…I was wondering if there are any facilities in WireMock Cloud to accomplish date math? For example, calculating the number of days between date_1 and date_2. I tried without success doing:
{{math '2023-08-01' '-' '2023-07-01'}}
and
{{math (parseDate '2023-08-01' format="yyyy-MM-dd") '-' (parseDate '2023-07-01' format="yyyy-MM-dd")}}
t
Hi Dan, I don’t think there’s a way to do durations in the templating language at this stage. You can do things like truncating and offsetting dates, but you always end up with another date value from these operations.
Adding an
{{interval}}
helper would make a great PR
👍 1
d
Excellent. Use case here is to be able to calculate upper and lower bounds when doing something like:
Copy code
# if either `joined_after` or `jointed_before` query parameters is present, response's `joined` key value should be with those bounds

# TODO 
# 1) calculate # of days difference between `now` and each query parameter
# 2) use calculated values as upper and lower bounds of randomInt

{{#assign 'dateOffset'}}-{{randomInt lower=1 upper=7300}} days{{/assign}}

{{#assign 'joinedDate'}}{{now offset=dateOffset format='yyyy-MM-dd'}}{{/assign}}