HubL / Twig : Comparing two unix timestamps - datetime

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?

Related

Date format not working, shows different date

I currently am working on a project, where I have to render events and I am stuck with the date format.
My variable {{ event.start }} renders this date in the website: 2021-08-27T00:00:00+02:00[Europe/Vienna]
When I want to return this date with the right format like that
{{ event.start|date("d.m.Y") }}
it shows this date, which is not true: 31.07.2021 (it should be 27.08.2021)
Any ideas what I am doing wrong?

How to filter an integer using the sort in twig

I want my project to be filter by the score and I am using a elasticsearch. now, the score have two variables: matchingScore and personalityScore. this two is should be added in the twig to get the actual score. Now, I dont know how to sort an integer since this is not an array and the sorting in the twig is required an array. This is the sample code:
{% for provider in matches | sort matchingScore[provider.id] + personalityScore[provider.id]('desc') %}
{% if matchingScore[provider.id] + personalityScore[provider.id] >= score_criteria %}
Please Help me. thanks.

Count days in Jekyll

I have a a Jekyll website and I would like to create a day counter, starting from 1 and then every day it should add +1 to the counter.
So today it would say:
Day 1
Tomorrow it should say
Day 2
The day after:
Day 3
is that possible to do in jekyll?
You just need to calculate the difference between two dates. There is some discussion about that here: https://stackoverflow.com/a/34615552/1645925
My favourite answer states:
{% assign today = site.time | date: '%s' %}
{% assign start = '20-01-2014 04:00:00' | date: '%s' %}
{% assign secondsSince = today | minus: start %}
{% assign hoursSince = secondsSince | divided_by: 60 | divided_by: 60 %}
{% assign daysSince = hoursSince | divided_by: 24 %}
Hours: {{hoursSince}}
Days: {{daysSince}}
I believe site.time refers to the server time that your site is hosted on but you can use 'now' to use the users time.
I assume you want a web page that tells you: today is day number 16 of the month.
Because Jekyll is a static site generator, all logic will only be executed during generation of the site. When you do not update/rebuild your website (daily), the counter does not increment. I think using javascript is the only solution for this problem.
Given my assumption, the answer is: No, Jekyll does not do this. You should use javascript for this.

How to display month in twig file using 0-11 arguments (jQuery FullCalendar)

I am trying to add a query string to a link in my twig file for the purpose of jumping to today's agenda in jQuery FullCalendar, but the months are based on a 0-11 structure rather than the standard 01-12.
I am using the following string to generate the query in my twig template:
View Today's Agenda
But using the "date_modify" and "-1 month" will not work if it's January as it will render "12" instead for the previous December. So, if it's January it needs to show as "0".
Is the way of doing this in Twig? It's not practical for me to render it in my Controller PHP as I'd have to do it many times due to my extensive range of pages in my CRM.
Thanks in advance
Michael
Try:
&m={{ ("now"|date("m"))-1 }}

Symfony 2 - Generate calendar month table with links to events in it

I have an Entity called Event, with fields startDate, startTime, endDate and endTime. startDate and endDate are dates of which endDate can be NULL if it is the same of startTime (I can change this behaviour if it makes things easier as I have no events yet). startTime and endTime can not be NULL. It also has an isOnDate(\DateTime $date) method, which returns true if the event will run on the given date.
It was like pain, but I finally generated an HTML table of any given calendar month, passing the day of week of the month's first day (firstDow) and the number of days in that month (numDays) as template variables.
The next step would be to make some table cells links to event or event listing pages if the given days has one or more events. Now I'm a bit stuck, as I don't know how to get the DateTime() object of each cell in a template.
Can someone give me a hint on this? Or am I making it totally wrong?
You can display DateTime Objects as Text Dates using Twig Filter date:
{{ event.startDate|date("m/d/Y") }}
You could use Ajax and jQuery to link dynamically your page with your database. You could start from this calendar code for Symfony2: http://www.symfocal.com

Resources