md-arif-shaikh / tzc

Time Zone Converter for Emacs
GNU General Public License v3.0
18 stars 1 forks source link

Converting times before and after summer time changes #7

Closed gambhiro closed 3 months ago

gambhiro commented 3 months ago

The conversion should take into account the date, i.e. convert the time at a given date, not assume "time as of today".

Today is 2024-03-30. Los Angeles already changed to summer time, but in Europe the clock will change tomorrow.

Converting the time:

11:00 Europe/Lisbon

M-x tzc-convert-time-at-mark

Selecting America/Los_Angeles, the result 04:00 is correct.

https://www.timeanddate.com/worldclock/meetingtime.html?day=30&month=3&year=2024&p1=133&p2=137&iv=0

But tomorrow Europe will change clocks to summer time, and for a time next week:

[2024-04-05 Fri 11:00 Europe/Lisbon]

M-x tzc-convert-org-time-stamp-at-mark

[2024-04-05 Fri 04:00 America/Los_Angeles]

Is not correct, the result should be 03:00.

https://www.timeanddate.com/worldclock/meetingtime.html?iso=20240405&p1=133&p2=137

md-arif-shaikh commented 3 months ago

Hi @gambhiro, thanks for catching this. I have pushed changes to take into account the date on which the conversion should be computed. Before this, it was assumed that the conversion is calculated on the current day. You can now check M-x tzc-convert-org-time-stamp-at-mark on [2024-03-30 11:00 Europe/Lisbon] for America/Los_Angeles.

gambhiro commented 3 months ago

That's excellent! DST is a headache both for computers (bugs) and for humans (losing sleep).

The next DST change for Lisbon is Oct 27, for Los Angeles is Nov 3.

I tried a few tests:

Both locations using DST:

[2024-04-03 11:00 Europe/Lisbon]

Selecting the line, then calling

M-x tzc-convert-org-time-stamp-at-mark

Prints:

[2024-04-03 Wed 03:00 America/Los_Angeles]

✅ Correct!

https://www.timeanddate.com/worldclock/meetingtime.html?day=3&month=4&year=2024&p1=133&p2=137&iv=0

A date when Europe is using DST, but USA not yet:

[2024-10-28 11:00 Europe/Lisbon]
[2024-10-28 Mon 04:00 America/Los_Angeles]

✅ Correct!

https://www.timeanddate.com/worldclock/meetingtime.html?day=28&month=10&year=2024&p1=133&p2=137&iv=0

Both using DST again:

[2024-11-04 11:00 Europe/Lisbon]
[2024-11-04 Mon 03:00 America/Los_Angeles]

✅ Correct!

https://www.timeanddate.com/worldclock/meetingtime.html?day=4&month=11&year=2024&p1=133&p2=137&iv=0