Dates and Times in Test Cases

Date and time values should be specified using a format corresponding to the format of the Field. For example, a Field 'AESTDAT' with format 'dd MMM yyyy' and Field 'AESTTIM' with format 'HH:nn' should be entered like this:

When I enter data:
  | DataPoint        | Value       |
  | AE.AE.AESTDAT[0] | 10 JAN 2020 |
  | AE.AE.AESTTIM[0] | 16:30       |
Then I should see field "AE.AE.AESTDAT[0]" has value "10 JAN 2020"
And I should see field "AE.AE.AESTTIM[0]" has value "16:30"

Partial dates and times

Partial dates and times should be entered using 'UN' and 'UNK' as in Rave:

When I enter data:
  | DataPoint        | Value       |
  | AE.AE.AESTDAT[0] | UN UNK 2020 |
  | AE.AE.AESTTIM[0] | 16:UN       |
Then I should see field "AE.AE.AESTDAT[0]" has value "UN UNK 2020"
And I should see field "AE.AE.AESTTIM[0]" has value "16:UN"

Incomplete dates and times

Incomplete dates and times should be entered using underscores as placeholders for the missing parts of the date. TrialGrid will enter these as empty in Rave. Underscores should also be used in verification steps.

When I enter data:
  | DataPoint        | Value       |
  | AE.AE.AESTDAT[0] | __ ___ 2020 |
  | AE.AE.AESTTIM[0] | 16:__       |
Then I should see field "AE.AE.AESTDAT[0]" has value "__ ___ 2020"
And I should see field "AE.AE.AESTTIM[0]" has value "16:__"

Note

Underscore characters in non-datetime fields will be entered into Rave.

Current date and time

The current date and/or time can be used in Test Cases using the 'now' keyword, and can be formatted for use in Rave with the 'dataformat' keyword.

{% set today = now()|dataformat('dd MMM yyyy') %}
{% set time = now()|dataformat('hh:nn') %}

When I enter data:
  | DataPoint        | Value       |
  | AE.AE.AESTDAT[0] | {{ today }} |
  | AE.AE.AESTTIM[0] | {{ time }}  |

Then I should see field "AE.AE.AESTDAT[0]" has value "{{ today }}"
And I should see field "AE.AE.AESTTIM[0]" has value "{{ time }}"

When the above Test Case steps are run, the current date and time will be inserted into the steps:

When I enter data:
  | DataPoint        | Value       |
  | AE.AE.AESTDAT[0] | 26 JAN 2023 |
  | AE.AE.AESTTIM[0] | 21:03       |

Then I should see field "AE.AE.AESTDAT[0]" has value "26 JAN 2023"
And I should see field "AE.AE.AESTTIM[0]" has value "21:03"

Note

The format string inside 'dataformat' should use Rave format codes.

Note

Because the syntax for applying the dataformat to 'now()' includes a pipe character ('|'), it cannot be inserted directly into tables such as the data entry table.

Note

'now()' returns a Python datetime 'utcnow'. Python methods can be applied, see below for example.

Note

Creating variables for the current date and time will give consistent values throughout. The following steps might have different time values when run:

{% set today = now()|dataformat('dd MMM yyyy') %}
{% set time = now()|dataformat('hh:nn') %}

When I enter data:
  | DataPoint        | Value       |
  | AE.AE.AESTDAT[0] | {{ today }} |
  | AE.AE.AESTTIM[0] | {{ time }}  |

Then I should see field "AE.AE.AESTDAT[0]" has value "{{ today }}"
And I should see field "AE.AE.AESTTIM[0]" has value "{{ now()|dataformat('hh:nn') }}"

See also

Python documentation: datetime

Offsets from current date and time

Date intervals can be added and substracted from the current date or time using the 'timedelta' keyword.

{% set today = now()|dataformat('dd MMM yyyy') %}
{% set tomorrow = (now() + timedelta(days=1))|dataformat('dd MMM yyyy') %}
{% set yesterday = (now() - timedelta(days=1))|dataformat('dd MMM yyyy') %}

{% set time = now()|dataformat('hh:nn') %}
{% set time_1_min = (now() + timedelta(minutes=1))|dataformat('hh:nn') %}
{% set time_5_min = (now() + timedelta(minutes=5))|dataformat('hh:nn') %}

When I enter data:
  | DataPoint        | Value           |
  | AE.AE.AESTDAT[0] | {{ today }}     |
  | AE.AE.AEENDAT[0] | {{ yesterday }} |

When I enter data:
  | DataPoint        | Value            |
  | AE.AE.AESTDAT[0] | {{ today }}      |
  | AE.AE.AESTTIM[0] | {{ time }}       |
  | AE.AE.AEENDAT[0] | {{ today }}      |
  | AE.AE.AEENTIM[0] | {{ time_5_min }} |

See also

Python documentation: timedelta