Repository navigation
Closed
Description
Looking at the parseDate function I think null falls into the final else block and new Date(null) does return 1970-01-01.
To fix could simply add one more if (isNil(v)) return undefined check before the existing if checks.
Lines 43 to 64 in 8f69a08
| function parseDate (v: string | Date, opts: NormalizedFullOptions, timezoneOffset?: number | string): LiquidDate | undefined { | |
| let date: LiquidDate | undefined | |
| const defaultTimezoneOffset = timezoneOffset ?? opts.timezoneOffset | |
| const locale = opts.locale | |
| v = toValue(v) | |
| if (v === 'now' || v === 'today') { | |
| date = new LiquidDate(Date.now(), locale, defaultTimezoneOffset) | |
| } else if (isNumber(v)) { | |
| date = new LiquidDate(v * 1000, locale, defaultTimezoneOffset) | |
| } else if (isString(v)) { | |
| if (/^\d+$/.test(v)) { | |
| date = new LiquidDate(+v * 1000, locale, defaultTimezoneOffset) | |
| } else if (opts.preserveTimezones && timezoneOffset === undefined) { | |
| date = LiquidDate.createDateFixedToTimezone(v, locale) | |
| } else { | |
| date = new LiquidDate(v, locale, defaultTimezoneOffset) | |
| } | |
| } else { | |
| date = new LiquidDate(v, locale, defaultTimezoneOffset) | |
| } | |
| return date.valid() ? date : undefined | |
| } |
However, with some more checking I am seeing a test already where it seems this is the expected behavior. I don't understand why, but if it is correct then I'll have to work around it.
liquidjs/test/integration/filters/date.spec.ts
Lines 24 to 26 in 8f69a08
| it('should treat nil as 0', () => { | |
| expect(liquid.parseAndRenderSync('{{ nil | date: "%Y-%m-%dT%H:%M:%S", "Asia/Shanghai" }}')).toEqual('1970-01-01T08:00:00') | |
| }) |
Activity
timbze commentedon Apr 6, 2026
I'd be happy to create PR if this logic should be changed.
harttle commentedon Apr 7, 2026
Thanks for the investigation. I checked shopify/liquid, it seems returning empty for this case. Let's align with the ruby version and change the test case above to equal
''.fix: null date should return empty (harttle#868)
fix: null date should return empty (#868) (#872)
chore(release): 10.25.5 [skip ci]
github-actions commentedon Apr 7, 2026
🎉 This issue has been resolved in version 10.25.5 🎉
The release is available on:
Your semantic-release bot 📦🚀