You're viewing legacy documentation for API Fortress (deployed via an on-premises container). To view documentation for the new SaaS version of API Fortress — now known as Sauce Labs API Testing and Monitoring (with Sauce Connect tunnels) — see API Testing on the Sauce Labs Cloud.
Have you ever needed to pass a future date as part of the request inside of a test? Perhaps as a check-in or check-out date? You could enter it as static value, but that means you would have to periodically update the date as time went on.
Creating a dynamic date in API Fortress is a simple solution for this sort of situation.
Here's the procedure:
- First, open the Composer and add a Set (variable):
- In the Variable component editor, enter the following:
- Var field: enter your variable name.
- Variable mode field: leave it as
- Value field: enter the following string:
Let's analyze the string mentioned above:
D.nowMillis(): returns the current Unix epoch in milliseconds
D.plusDays(): returns the provided milliseconds, plus the provided number of days (in our example, we have added 35 days to today's date)
D.format(): creates a timestamp with the given format, using the current timezone (in our example
As result, you will have something like
You can obtain a past date, starting from today's date with the following string:
You can also create a date based on a specified time zone:
The above string create the same date as our first example using New York (EST) as the timezone.
For more details, see our reference page.