locomotivecms / engine

A platform to create, publish and edit sites
http://www.locomotivecms.com
Other
2.32k stars 625 forks source link

parse_date does not work as described in the documentation #1410

Open greyskin opened 10 months ago

greyskin commented 10 months ago

The title says it all. I'm reluctant to suggest updates to the documention until I get some feedback about the intended use of this filter.

Documentation: https://doc.locomotivecms.com/docs/filters#parse_date

Copy and paste directly from the documentation example: {{ '2015-09-26' | parse_date }} Result: Renders nothing in wagon and engine

It's unclear from the documentation how the format option is supposed to be used. Based on the money filter options, I tried: {{ '2015-09-26' | parse_date: format: '%m/%d/%Y' }} Result: error message - "no implicit conversion of Hash into String" (wagon and engine)


I found this GitHub issue where parse_date is mentioned and the example given is: {% assign date_a = "2015-11-01" | parse_date: '%Y-%m-%d' %}

This appears to be more acurate than the documentation. The following snippet works in both wagon and engine:

{% assign myDate = '08-28-2023' | parse_date: '%m-%d-%Y' %}
{% if now > myDate %}
    today comes after myDate
{% else %}
    today comes before myDate
{% endif %}

Note the American date format mm-dd-yyyy. This is how I know that the parse_date filter is working here. If I run the same snippet without the parse_date filter, I get an error message - "comparison of ActiveSupport::TimeWithZone with String failed".

It seems to me that parse_date is intended for use in Liquid tags, not objects, i.e. with {% and %} delimiters, not {{ and }}.