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

setting timezone for specific template #553

Closed
amit777 opened this issue Nov 7, 2022 · 8 comments
Closed

setting timezone for specific template #553

amit777 opened this issue Nov 7, 2022 · 8 comments

Comments

@amit777
Copy link
Contributor

amit777 commented Nov 7, 2022

Hi, we have a need to be able to set the timezone for the date filter defined here: https://liquidjs.com/filters/date.html

Is it possible to update the date filter to have an optional second parameter of the timezone?

eg: {{ article.published_at | date: "%a, %b %d, %y":"America/Los_Angeles" }}

I didn't quite understand the note in the documentation about how to set the timezon in liquid options.

@amit777
Copy link
Contributor Author

amit777 commented Nov 7, 2022

From what I can tell, the current option is to set the timezone for the whole rendering engine. Unfortunately this won't work for our use-case as different templates need to be able to render dates in different timezones.

@harttle
Copy link
Owner

harttle commented Nov 10, 2022

Thank you @amit777 , the docs for timezoneOffset surely need to be elaborated with more details. Basically it's used to specify a timezone offset globally (setting to 0 means UTC).

Along with that, I think we can support a timezone for each date call as well. While I don't want to include and maintain a timezone database inside liquidjs, we need make use of JavaScript Data whenever we can. Maybe use the same format to specify a timezone as in new Date.

@amit777
Copy link
Contributor Author

amit777 commented Nov 10, 2022

I'm open to anything. We have users who have different time zone setting, so the global option is problematic for us.

github-actions bot pushed a commit that referenced this issue Nov 27, 2022
# [9.43.0](v9.42.1...v9.43.0) (2022-11-27)

### Features

* support timezone offset argument for date filter, [#553](#553) ([7a71485](7a71485))
@harttle
Copy link
Owner

harttle commented Nov 27, 2022

I find timezone string like America/Los_Angeles is only supported in toLocaleDateString(), and cannot be converted to timezone offset for use of strftime. So I supported specifying a timezone offset for now. Still looking for better options.

timezoneoffset is defined as https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset

// 360 is for -06:00 timezone
{{ "1990-12-31T23:00:00Z" | date: "%Y-%m-%dT%H:%M:%S", 360}}

@amit777
Copy link
Contributor Author

amit777 commented Nov 29, 2022

Maybe this can be a optional filter that depends on extranal modules? Like a liquidjs extras repo?

github-actions bot pushed a commit that referenced this issue Nov 29, 2022
# [10.1.0](v10.0.0...v10.1.0) (2022-11-29)

### Features

* timezone name for `opts.timezoneOffset` and `date` argument, fixes [#553](#553) ([89c6c76](89c6c76))
@github-actions
Copy link

🎉 This issue has been resolved in version 10.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@harttle
Copy link
Owner

harttle commented Nov 29, 2022

I came across a stackoverflow and find it's possible to support timezone names, now can be used like

{{ "2021-01-01T23:00:00Z" | date: "%Y-%m-%dT%H:%M:%S", "America/New_York" }}

Now LiquidOptions.timezoneOffset supports timezone name as well.

Note: The timezone names support depends on JavaScript Date in your browser or Node.js. It can be tricky for date literals when DST is active. It can be viewed as 2 steps

  1. use the specified date (literal or variable from scope, this date is already absolute) to determine whether DST is active
  2. determine timezone offset depending on whether DST is active
  3. call strftime with this offset

@amit777
Copy link
Contributor Author

amit777 commented Dec 9, 2022

Hi there.. sorry to comment on closed issue. But it looks like the documentation on https://liquidjs.com/filters/date.html should be updated to include the new TimeZone parameter.

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

No branches or pull requests

2 participants