Skip to content

TimeDifference

The TimeDifference object represents time difference between 2 points in time.

classDiagram
  direction LR
  class TimeDifference{
    bool isNegative
    int days
    int hours
    int minutes
    int seconds
    int timeInSeconds
    string difference
    string differenceLong
    string differenceShort
  }

It is possible to render the time by rendering the object directly.

source
{% set event = ObjectApi.getDateTime("2022-09-10 12:30:15") %}
{% set time = ObjectApi.getDateTime("2022-09-12 14:45:45") %}

{% set timeDifference = time.timeDifference(event) %}

{{ timeDifference }}
output
2d 2:15:30

Properties

Attribute name Type Description
isNegative bool Returns true if difference in seconds is lower than zero
days int Number of days
hours int Number of hours
minutes int Number of minutes (from 0 to 59)
seconds int Number of seconds (from 0 to 59)
timeInSeconds int Time representation in seconds
difference string Formatted value of time difference
differenceLong string Formatted full value of time difference
differenceShort string Formatted short value of time difference

Examples

isNegative property

{% set event = ObjectApi.getTime("13:30:15") %}
{% set time = ObjectApi.getTime("12:30:15") %}

{% set timeDifference = time.timeDifference(event) %}

{% if timeDifference.isNegative %}
    {{ timeDifference.timeInSeconds }} seconds before the event
{% endif %}
3600 seconds before the event

days property

{% set event = ObjectApi.getDateTime("2022-09-10 12:30:15") %}
{% set time = ObjectApi.getDateTime("2022-09-12 12:30:15") %}
{% set timeDifference = time.timeDifference(event) %}

{{ timeDifference.days }}
2

hours property

{% set event = ObjectApi.getTime("13:30:15") %}
{% set time = ObjectApi.getTime("14:45:45") %}

{% set timeDifference = time.timeDifference(event) %}
{{ timeDifference.hours }}
1

minutes property

{% set event = ObjectApi.getTime("13:30:15") %}
{% set time = ObjectApi.getTime("14:45:45") %}

{% set timeDifference = time.timeDifference(event) %}
{{ timeDifference.minutes }}
15

seconds property

{% set event = ObjectApi.getTime("13:30:15") %}
{% set time = ObjectApi.getTime("14:45:45") %}

{% set timeDifference = time.timeDifference(event) %}
{{ timeDifference.seconds }}
30

timeInSeconds property

{% set event = ObjectApi.getTime("13:30:15") %}
{% set time = ObjectApi.getTime("14:45:45") %}

{% set timeDifference = time.timeDifference(event) %}
{{ timeDifference.timeInSeconds }}
4530

difference property

{% set event = ObjectApi.getDateTime("2022-09-10 12:30:15") %}
{% set time = ObjectApi.getDateTime("2022-09-12 14:45:45") %}

{% set timeDifference = time.timeDifference(event) %}
{{ timeDifference.difference }}
2d 2:15:30

differenceLong property

{% set event = ObjectApi.getDateTime("2022-09-10 12:30:15") %}
{% set time = ObjectApi.getDateTime("2022-09-12 14:45:45") %}

{% set timeDifference = time.timeDifference(event) %}
{{ timeDifference.differenceLong }}
2d 2h 15m 30s left

differenceShort property

{% set event = ObjectApi.getDateTime("2022-09-10 12:30:15") %}
{% set time = ObjectApi.getDateTime("2022-09-12 14:45:45") %}

{% set timeDifference = time.timeDifference(event) %}
{{ timeDifference.differenceShort }}
2d