Skip to main content

<dateTime>

The <dateTime> tag sets the current time for the test case. When running the test case, the following JS API methods will return the specified time:

caution
If a test case checks something dependent on the current time, it should always include the <dateTime> tag. Otherwise the test case will be unstable.

Body

The tag should include the date and time in the following format: yyyy-MM-dd HH:mm:ss. The time zone is not specified and is treated as UTC.

How to use

Here is a script where the bot uses different phrases to greet the user depending on the time of day:

# Here, we import the Moment.js library from the zb-common system project.
require: dateTime/moment.min.js
module = sys.zb-common

theme: /

state: Start
q!: $regex</start>
script:
$temp.hour = moment($jsapi.currentTime()).hour();
if: $temp.hour >= 0 && $temp.hour < 6
a: Good night!
elseif: $temp.hour >= 6 && $temp.hour < 12
a: Good morning!
elseif: $temp.hour >= 12 && $temp.hour < 18
a: Good day!
else:
a: Good evening!

This script can be covered by the following test:

<test>
<test-case>
<dateTime>2023-06-23 15:30:00</dateTime>
<q>/start</q>
<a>Good day!</a>
</test-case>

<test-case>
<dateTime>2023-06-23 21:30:00</dateTime>
<q>/start</q>
<a>Good evening!</a>
</test-case>
</test>