I’m really puzzled and can’t understand why my {{ time }}
returns an empty value.
I’m trying to calculate the difference between the time currently and a booking time in Shopify. For the booking I have the date (first line_item.property) and the time (second one) coming separately. I want to add one to another and then compare it to the current time, but before I can do the math I have tried to display the different variables I have created.
{{ now }}
& {{ date }}
work fine but for {{ time }}
it returns an empty value. On the other hand if instead of assigning it a value name I just display the line.item.property
it works just fine.
Can you help me understand what I am doing wrong here?
{% assign today = 'now' | date: '%s' %}
{% for order in customer.orders %}
{%- for line_item in order.line_items -%}
{% for property in line_item.properties limit:1 %}
{% assign date = property.last | date: '%s' %}
{% endfor %}
{% for property in line_item.properties offset:1 %}
{% assign time = property.last | date: '%s' %}
{% endfor %}
{%- endfor -%}
{{ now }} - {{ date }} - {{ time }}
{% endfor %}
2
Answers
Thanks Charles that really unblocked me. Posting here the final version I went with as I needed to compare exact time and not simply the date of the order.
By using
plus: 0
you can convert thestring
tointeger
, this will enable math operation for your comparison.check with
{% unless line_item.properties == empty %}
to see if properties exist.{% assign date = property.last | date: '%s' %}
, the variableproperty.last
must follow a well-formatted dates fordate
to work. liquid-date-formatproblem with
offset:1
, if the array only has 1line_item.properties
this will not run at all. Hencetime
is empty; or it exist butproperty.last
does not have adate
format.