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

Add a way to retrieve a UTC now datetime in Liquid #12339

Merged
merged 4 commits into from
Sep 16, 2022
Merged

Conversation

Skrypt
Copy link
Contributor

@Skrypt Skrypt commented Sep 5, 2022

utc: {{ "utc_now" | local | date: "%c" }}
local : {{ "now" | local | date: "%c" }}
local is the default : {{ "now" | date: "%c" }}

image

At the same time I'm questioning the TimeZoneFilter name now. "local" doesn't make sense anymore if we do this. The idea of the TimeZoneFilter should be to allow returning a local DateTime or a DateTime affected by an offset. Here, we should probably consider creating a filter that allows passing a TimeZoneId or an Offset value simply. Need to think about the design. But at the same time | local here doesn't make sense to be required to retrieve a UTC DateTime value.

Else, a refactor of this filter might become a breaking change. Maybe better simply create a new one.

@hishamco
Copy link
Member

hishamco commented Sep 5, 2022

Why we didn't add UTC into Fluid? Or extend Now filter to support UTC through pipe operator

{{ "now" | utc | date: "%c" }}

@Skrypt
Copy link
Contributor Author

Skrypt commented Sep 5, 2022

image

The first value there is what you are suggesting which doesn't work.
But I think you are right. This is what would be needed now. I think that the TimeZoneFilter here has no use anymore because the current timezone of the tenant is now passed to Fluid by default. It was not the case when we did this filter 4 years ago.

And rename TimeZoneFilter to LocalTimeZoneFilter.
@Skrypt
Copy link
Contributor Author

Skrypt commented Sep 5, 2022

After adding UtcTimeZoneFilter:

    local is the default: {{ "now" | date: "%c" }}<br />
    local: {{ "now" | local | date: "%c" }}<br />
    utc: {{ "now" | utc | date: "%c" }}<br />

image

@Skrypt
Copy link
Contributor Author

Skrypt commented Sep 5, 2022

Why we didn't add UTC into Fluid? Or extend Now filter to support UTC through pipe operator

It is not just "now" but all DateTimes that are converted when passed in these filters. So, yes, adding a UTC one makes sense then. It will basically remove or add your tenant timezone offset to these DateTimes.

@Skrypt Skrypt merged commit 5d14881 into main Sep 16, 2022
@Skrypt Skrypt deleted the skrypt/liquid-utc_now branch September 16, 2022 18:56
@sebastienros
Copy link
Member

Relevant PR in Fluid to parse date time inputs (including "now") sebastienros/fluid#431

There is a time_zone filter to convert to any timezone. ,e.g., {{ "now" | time_zone: 'utc' }}

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

Successfully merging this pull request may close these issues.

3 participants