-
-
Notifications
You must be signed in to change notification settings - Fork 506
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
Timezone Errors with post dates #2737
Comments
Updated as I figured out the published date is
not |
Most of the date functionality was fixed in 2.x, but it could very well be that I missed the |
Did some local tests @gchtr and I recreated the same two outcomes that @asecondwill describes be it with different dates and time zones. {{ post.post_date|time_ago }} does not seem to take the timezone into account because it relies on {{ post.date }} as stated in the Timber docs only returns the publication date without the time. So when using |time_ago on that it will always count use that day at midnight. That in combination with our first issue gives leads to inexplicable behavior. Using |
I found out what the issue was and added a fix in #2758.
Correct. You should use a full date and time string when using {{ post.date('U')|time_ago }}
{{ post.date(constant('DATE_ATOM'))|time_ago }}
You can use
Just a note here. As of WordPress 5.3, it’s not recommended to use |
@gchtr just wanted to let you know the results of my tests too, as they're all pretty inconsistent.
I have an article I published 15 minutes ago. Let's start from your suggestions: ✅ ❌ ❌ Other tests: ❌ ❌ |
@alessandro-newzoo My suggestions don’t work yet. But they should as soon as the pull request #2758 is merged. Maybe you can check it out when you test the fix by installing from the pull request’s branch? composer require timber/timber:dev-2.x-time-ago |
@gchtr ohhh sorry about that, I misinterpreted your previous comment! For now, for some reason, Thank you SO much both for the PR and for providing a snippet that finally made me stop scratching my head after 2 days haha! |
@alessandro-newzoo That’s alright. I figured the first line in my comment can easily missed :).
I think that works because the
You’re welcome! Dates and time made me scratch my head a lot in the past. I took quite some time to eventually "get it". |
Fixed in #2758. |
Expected Behavior
I'm expecting the timezone setting in wp-admin to be used by the timber filters to output the time_ago
Actual behavior
My site is set to Australia/Adilade
{{ post.date('j F Y H:i') }} shows the published date in the correct timezone.
Time Ago
{{ post.post_date|time_ago }}
Time ago says "In about 7 hours" at 1230 UTC when I'm testing, again the publish date is 1930 today (16th May) - Adilaide time, which was 3 hours ago.
UPDATE: if i try
{{ post.date|time_ago }}
I get 14hours ago. which is still wrong, it's 2230 in Adilade so 3 hours ago.
Steps to reproduce behavior
Time ago
{{ post.post_date|time_ago }}
with composer twig:
"timber/timber": "2.0.0.beta-1",
Notes
I got the same behaviour in Timber 1, so upgraded thinking this had been fixed in 2 having read through the tickets here.
What version of Timber are you using?
2.0.0.beta-1
What version of WordPress are you using?
Wordpress 6.2
What version of PHP are you using?
8.0
How did you install Timber?
Installed or updated Timber through Composer
The text was updated successfully, but these errors were encountered: