Closed mcurmei627 closed 6 months ago
I'm gonna quote my commit message, I think I found an easy solution that I like:
store timzeone indication together with events
Events now have a "local_zero_hour" column which represents the start of the
day (00h00m00s on the day of the event, which is midnight on the
previous calendar day).
They have two other dates, "created_at" and "updated_at".
Neither of these datetimes contain timezone information,
they all store times as UNIX timestamps, number of
milliseconds since the UNIX epoch (January 1st 1970, midday GMT),
not including leap-seconds.
That means if dateA < dateB then A occurred before B.
But we do not know the local time when the events occurred.
Dates are complicated.
It's hard to know whether any given interface displays
a date in your timezone or some other one,
and conversions are often counter-intuitive.
I propose this encoding whose advantage is that no matter the representation
of dates chosen by the interface, you can always know the subjective
local time by counting the time elapsed between "local_zero_hour" and
either "created_at" or "updated_at", which are just plain numbers
and all these dates use the same convention whatever it is.
So to get an event's local time,
you just need to compute "created_at" - "local_zero_hours"
and that will give you when in milliseconds starting from midnight
the event happened for the participant.
I think that's easy to work with in any language, and easy to conceptualize.
(I dunno, always struggled with timezones)
Here's an example:
I pretend my browser is in Shanghai by closing all instances of chromes and then in a terminal:
TZ='Asia/Shanghai'; export TZ
google-chrome
the Google Chrome that opens will think it is in Shanghai (If I open the console and type new Date()
it displays: Wed Aug 30 2023 22:15:25 GMT+0800 (China Standard Time)`.
Now I browse youtube a bit and I get events with times like:
local_zero_hour = '2023-08-29 18:00:00';
created_at = '2023-08-30 16:15:21.747';
So if I wanna know the participant's local time when this event occurred I can do:
dt = new Date(created_at) - new Date(local_zero_hour);
hours = dt / 1000 / 60 / 60; // "22.2560...."
round_hours = Math.floor(hours); // "22"
minutes = Math.floor((hours - round_hours) * 60); // "15"
local_participant_time= `${round_hours}:${minutes}`; // "22:15"
and what do you know, it works:
Yes there are 4 minutes delay because it took me some time to write this up but this seems conclusive.
And that's the option that requires the fewest changes I think.
What do you think?
thank you @djfm ; this seems to work well for my recent browsing; and the solution is very elegant.
is it the extension that computes the local_zero_hour
for every event?
yes, the extention justs sends to the server the client's UTC value of midnight for them (well now that I think of it, the time is according to their system's settings, not necessarily their geographic location, but normally they match)
On Wed, 30 Aug 2023, 19:46 Mihaela Curmei, @.***> wrote:
thank you @djfm https://github.com/djfm ; this seems to work well for my recent browsing; and the solution is very elegant. is it the extension that computes the local_zero_hour for every event?
— Reply to this email directly, view it on GitHub https://github.com/Algorithmic-Personalization/ytdpnl-extension/issues/2#issuecomment-1699599903, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALESE7EGL3ADJV3DX57OD3XX54BBANCNFSM6AAAAAA4CDKJLU . You are receiving this because you were mentioned.Message ID: @.*** com>
Note that all the other dates are in the server's timezone (don't remember which one it is) but I do not think it matters much, most other objects can be shared by multiple participants (videos, etc.), so their timezones don't mean much.
You may still have some difficulty knowing the participant local time of the start of a session, but you can deduce that from the time of the first event of the session if need be.
On Wed, 30 Aug 2023, 20:02 FM dj, @.***> wrote:
yes, the extention justs sends to the server the client's UTC value of midnight for them (well now that I think of it, the time is according to their system's settings, not necessarily their geographic location, but normally they match)
On Wed, 30 Aug 2023, 19:46 Mihaela Curmei, @.***> wrote:
thank you @djfm https://github.com/djfm ; this seems to work well for my recent browsing; and the solution is very elegant. is it the extension that computes the local_zero_hour for every event?
— Reply to this email directly, view it on GitHub https://github.com/Algorithmic-Personalization/ytdpnl-extension/issues/2#issuecomment-1699599903, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALESE7EGL3ADJV3DX57OD3XX54BBANCNFSM6AAAAAA4CDKJLU . You are receiving this because you were mentioned.Message ID: @.*** com>
The server records UTC time, @djfm correct me if I am wrong.
Does the extension have access to time zone information? If so, we can add a time zone column to the events.
If not, then that should not be a huge issue, at least for now