I made a custom section for my stores sale banner, schedule the time when its removed or added.
However the end date keep getting displayed wrong.
It should be month/date/year hour:minute:second.
But it swishes the date and month. This only for the end_date part of the code.
(above what input fields)
(Above what is shown on the page)
The liquid part:
{% assign start_date = section.settings.bsstart_time | date: "%m/%d/%Y %H:%M:%S" %}
{% assign end_date = section.settings.bsend_time | date: "%m/%d/%Y %H:%M:%S" %}
{% assign now_date = "now" | date: "%m/%d/%Y %H:%M:%S" %}
The schema part:
{
"type": "text",
"id": "bsstart_time",
"label": "Banner start time (optional)",
"info": "mm/dd/yyyy hh:mm:ss"
},
{
"type": "text",
"id": "bsend_time",
"label": "Banner end time (optional)",
"info": "mm/dd/yyyy hh:mm:ss"
}
dates in templates may be cached, “now” is NOT a reliable source of truth to disable behavior and if utilizing frontend time
user-side-time for validation is specifically an unreliable source of time comparison (customers local browser|OS time).
Use a tool like shopify-flow to change metafields, or more advanced theme settings or files, also see more advanced tools like usemechanic app https://tasks.mechanic.dev/?q=theme%20time .
@mns-burg Join us in sanity, use YYYY-MM-DD when dealing storing date values with the ISO-8061 format https://en.wikipedia.org/wiki/ISO_8601
{% assign end_date = "2024-11-01" | date: "%m/%d/%Y" %}
otherwise you need to use a unix timestamp, or dig into WHY ruby’s strftime via liquid does this when the day value is smaller than 12 (12 months)
https://shopify.dev/docs/api/liquid/filters/date
If using the shopify-cli is has a liquid theme console for testing logic
https://shopify.dev/changelog/liquid-console-test-and-evaluate-liquid-snippets-quickly-using-shopify-cli
https://shopify.dev/docs/api/shopify-cli/theme/theme-console
Maintenance Nits: Unless using locale files label the input format AND make it clear what the expected output format is too;
Namespace fully and clearly avoiding any ambiguity for future you or other devs.
section.settings**.**bsend_time should be section.settings.banner_sale_end_time etc. it’s not the 1960’s needing to save 10 characters , and s + end infers “send” but nothing is being sent.