harttle / liquidjs

A simple, expressive, safe and Shopify compatible template engine in pure JavaScript.
https://liquidjs.com
MIT License
1.52k stars 238 forks source link

date filter should return parsed input when no format is provided #573

Closed sebastienros closed 3 months ago

sebastienros commented 1 year ago

Expected:

image

Actual: https://liquidjs.com/playground.html#e3sgJ25vdycgfCBkYXRlIH19Cnt7ICcyMDIyLTEyLTA3VDIyOjIyOjE4JyB8IGRhdGUgfX0K,e30=

harttle commented 1 year ago

Actually in my local shopify/liquid, it yields an error:

liquid/lib/liquid/standardfilters.rb:681:in `date': wrong number of arguments (given 1, expected 2) (ArgumentError)

But I do think it's better to output something instead of throwing. Now what I can find in JavaScript (with most similarity) is Date.toString(), what do you think?

> (new Date()).toString()
Thu Dec 22 2022 22:40:58 GMT+0800 (Taipei Standard Time)'
harttle commented 1 year ago

Date.toString()

I find this approach is not feasible for TimezoneDate. Now I'm trying to set the default format string to '%A, %B %-e, %Y at %-l:%M %P %z' when it's not provided, so that the use case you provided can pass the test.

It seems OK in this test case: https://github.com/harttle/liquidjs/blob/3f21382d43cafa1e32162e58adabd22d5c3709ed/test/integration/filters/date.ts#L70-L72

The timezone is specified so that this test case can be env independant, more realistic use case is:

https://github.com/harttle/liquidjs/blob/3f21382d43cafa1e32162e58adabd22d5c3709ed/test/integration/filters/date.ts#L9-L11