Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preserveTimezones has no effect #784

Open
theonlypwner opened this issue Jan 3, 2025 · 3 comments
Open

preserveTimezones has no effect #784

theonlypwner opened this issue Jan 3, 2025 · 3 comments

Comments

@theonlypwner
Copy link

On version 10.20.0, preserveTimezones doesn't seem to work at all.

const { Liquid } = require('liquidjs')

new Liquid({ preserveTimezones: true, dateFormat: '%Y-%m-%d %H:%M:%S %z' }).parseAndRender(
  `{{ "2025-01-02 03:04:05 -0100" | date }}`
).then(console.log)

Actual output: (machine local timezone is UTC-7)
2025-01-01 21:04:05 -0700

Expected output:
2025-01-02 03:04:05 -0100

github-actions bot pushed a commit that referenced this issue Jan 4, 2025
## [10.20.1](v10.20.0...v10.20.1) (2025-01-04)

### Bug Fixes

* break/continue stops whole template, [#783](#783) ([5f1a4cf](5f1a4cf))
* enumerate plain objects in where/where_exp, [#785](#785) ([#788](#788)) ([25ef104](25ef104))
* preserveTimezones support for RFC2822 date, [#784](#784) ([59cf3c0](59cf3c0))
@harttle
Copy link
Owner

harttle commented Jan 5, 2025

Please try 10.20.1, let me know if there's still any issue.

@theonlypwner
Copy link
Author

It is working in 10.20.1 for my particular use case, but I noticed that TIMEZONE_PATTERN requires the minutes to be present, and I've seen some other people use formats that include only the timezone offset hours and imply 0 for minutes, such as this example using the same test script from my original post:

  • 2025-01-02 03:04:05 -01 input
  • 2025-01-01 21:04:05 -0700 actual output
  • 2025-01-02 03:04:05 -0100 expected output

Also, the parsing doesn't seem to work if T is present, as in this example:

  • 2025-01-02T03:04:05 -01:00 input
  • 2025-01-02T03:04:05 -01:00 actual output
  • 2025-01-02 03:04:05 -0100 expected output

However, it works if the space is removed, as with the input 2025-01-02T03:04:05-01:00 (actual output 2025-01-02 03:04:05 -0100 is expected).

@harttle
Copy link
Owner

harttle commented Jan 6, 2025

We can support time zones without minutes. But not for cases when it’s not a valid init string for JavaScript Date. As T is required for ISO9601.

You can check whether it’s a LiquidJS issue or JavaScript issue by passing the string to ‘new Date’.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants