HubL / Twig : Comparing two unix timestamps

445 Views Asked by At

I'm trying to find the date and time difference between two unix values. In HuBL, I have currently:

{% set event_date_and_time = table_data_dict.event_time|unixtimestamp %}
{% set current_time_and_date = local_dt|unixtimestamp %}

{% if current_time_and_date  >= event_date_and_time %}
  event is live
{% else %}
  event is not live
{% endif %}

table_data_dict.event_time is the value from the date and time field in the database.

Running the following:

Event: {{ event_date_and_time }} <br>
Current: {{ current_time_and_date }}

Produces the following results:

Event: 1596623700000
Current: 1596620020929

Test scenarios:

Test 1:

The date and time I have set in the database (what event_date_and_time is) is 10th August 2020 12pm.

The if statement echos event is not live - which is correct.

Test 2:

The date and time now, in the database is set to a day before todays date (so 4th august 2020 12:00pm) - the event is essentially live.

The if statement echos event is live - which again, is correct.

Test 3:

Now, currently for me, it's 11:00am (5th Aug 2020). If, in the database, I change the date and time to 5th August 2020 11:10am. It produces the following results:

At 10:55am, when I check the if statement, it will say event is not live (correct, it's live at 11am).

Now, when I check at 11am (when the event is live) it says event is not live.

When I continue to wait and check again at 11:05am, it still says event is not live.

Unsure why? I have cleared cache, it's not a caching issue, unsure why it's performing like so?

0

There are 0 best solutions below