marcreichel/alpine-timeago

How to deal with time zones?

hankhank10 opened this issue · 2 comments

I am using this plugin to show a refer to a datetime stored in a database. My database stores the datetime in UTC time, which causes issues for users in different timezones.

For instance, those in Continental Europe will see a timestamp of now as "two hours ago".

Is there a way to have the plugin use UTC time rather than the user's local time?

@hankhank10 When you provide the timezone to the date time string everything should work as expected I think.

Here's an example:

Currently, it's 7:35 where I live.

<div x-data="{ date: '2022-04-08T05:35:00' }" x-timeago="date"></div>
<!-- would display "2 hours ago" for me -->
<div x-data="{ date: '2022-04-08T05:35:00+00:00' }" x-timeago="date"></div>
<!-- would display "just now" for me -->

Thank you, that was my issue. Now fixed, appreciate the help.