liquidjs icon indicating copy to clipboard operation
liquidjs copied to clipboard

date filter should return parsed input when no format is provided

Open sebastienros opened this issue 2 years ago • 2 comments
trafficstars

Expected:

image

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

sebastienros avatar Dec 20 '22 23:12 sebastienros

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 avatar Dec 22 '22 14:12 harttle

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

harttle avatar Jan 02 '23 17:01 harttle