Skip to content

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

Merged
Skrypt merged 4 commits intomainfrom
skrypt/liquid-utc_now
Sep 16, 2022
Merged

Add a way to retrieve a UTC now datetime in Liquid#12339
Skrypt merged 4 commits intomainfrom
skrypt/liquid-utc_now

Conversation

@Skrypt
Copy link
Copy Markdown
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.

@Skrypt Skrypt requested a review from deanmarcussen September 5, 2022 16:06
@hishamco
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 requested a review from agriffard as a code owner September 5, 2022 19:49
@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
Copy Markdown
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