Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.4K Views
|
7 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Daylight saving time - timezone conversion trouble

Posted 3 years ago

Hi,

in the last week of October, when switching back from daylight saving time to normal time, the hour between 2am and 3am exists twice, with different offsets. Here Mathematica mixes up:

stmptbl = {DateObject[{2022, 10, 29, 23, 30, 0}, TimeZone -> 0], 
  DateObject[{2022, 10, 30, 0, 30, 0}, TimeZone -> 0], 
  DateObject[{2022, 10, 30, 1, 30, 0}, TimeZone -> 0], 
  DateObject[{2022, 10, 30, 2, 30, 0}, TimeZone -> 0]}

stmptbl2 = TimeZoneConvert[#, "Europe/Berlin"] & /@ stmptbl

The third entry in the result

{Sun 30 Oct 2022 01:30:00CEST,
Sun 30 Oct 2022 02:30:00CEST,
Sun 30 Oct 2022 02:30:00CEST,
Sun 30 Oct 2022 03:30:00CET}

is wrong: this is no longer daylight saving time, but standard time ("winter time"). For the reverse conversion

TimeZoneConvert[#, 0] & /@ stmptbl2

you obtain:

{Sat 29 Oct 2022 23:30:00GMT,
Sun 30 Oct 2022 01:30:00GMT,
Sun 30 Oct 2022 01:30:00GMT,
Sun 30 Oct 2022 02:30:00GMT} 

Here the second entry is wrong and deviates by one hour.

I assume this is a bug (or rather: two bugs). Can anyone suggest a workaround?

Yours,

Bernd.

POSTED BY: Bernd Günther
7 Replies
Posted 3 years ago

No, I do not agree.

The day in question is 25h long, but your clock holds only 24h - so there must be something special here. The hour between 2am and 3am is run twice, and for distinction the first run is labelled "A" and the second "B".

So a valid conversion of DateObject[{2022, 10, 30, 0, 30, 0}, TimeZone -> 0] to "Europe/Berlin" would be 2022-10-30 02A:30:00 "Europe/Berlin" equivalently 2022-10-30 02:30:00 CEST equivalently 2022-10-30 GMT+2.

A valid conversion of DateObject[{2022, 10, 30, 1, 30, 0}, TimeZone -> 0] to "Europe/Berlin" would be 2022-10-30 02B:30:00 "Europe/Berlin" equivalently 2022-10-30 02:30:00 CET equivalently 2022-10-30 GMT+1.

The convention chosen by mathematica is not well defined, a random choice has been made. This will neccessarily lead to trouble, as I have shown when converting back to timezone 0.

In addition to that, with mathematica's current convention, the "B"-hour cannot be represented at all in "Europe/Berlin".

POSTED BY: Bernd Günther
Posted 3 years ago

Just a clarification, I was applying the convention where I live, which is to set the clocks back from 2am to 1am. It sounds like your convention is to set the clocks back from 3am to 2am. So, my specific examples might not make sense.

POSTED BY: Eric Rimbey
Posted 3 years ago
POSTED BY: Eric Rimbey
Posted 3 years ago

And just for kicks:

TimeZoneOffset["Europe/Berlin", {2023, 3, 26, 2, 30, 0}]

{}

So, Mathematica doesn't commit to an offset for this time specification.

Also:

TimeZoneConvert[DateObject[{2023, 3, 26, 1, 30, 0}, TimeZone -> "Europe/Berlin"], "GMT"]

DateObject[List[2023, 3, 26, 0, 30, 0], "Instant", "Gregorian", "GMT"]

TimeZoneConvert[DateObject[{2023, 3, 26, 2, 30, 0}, TimeZone -> "Europe/Berlin"], "GMT"]

DateObject[List[2023, 3, 26, 1, 30, 0], "Instant", "Gregorian", "GMT"]

TimeZoneConvert[DateObject[{2023, 3, 26, 3, 30, 0}, TimeZone -> "Europe/Berlin"], "GMT"]

DateObject[List[2023, 3, 26, 1, 30, 0], "Instant", "Gregorian", "GMT"]

These seem all reasonable choices. Your A/B convention doesn't fix the inverse problem of only 23 hours during the day when daylight saving begins, but Mathematica does something sensible.

Really, Mathematica has all of the knowledge that you need to do your time-related computations correctly.

POSTED BY: Eric Rimbey
Posted 3 years ago

Hi Eric, no, my objection is that CEST equals GMT+2 and CET equals GMT+1, therefore the third entry above is definitely wrong (timezone is a [neccessary for completeness] attribute of a datetime object, no matter how you represent it). Futher, the specification "DateObject[List[2022, 10, 30, 2, 30, 0], "Instant", "Gregorian", "Europe/Berlin"]" is ambiguous, and if mathematica represents the object internally like that they won't be able to fix this. For a well defined representation in this case you need offsets.

Unfortunately, this means that I have to do my conversion manually, and as it appears, mathematica contains more timezone bugs ...

POSTED BY: Bernd Günther
Posted 3 years ago

Hi Eric, no, my objection is that CEST equals GMT+2 and CET equals GMT+1, therefore the third entry above is definitely wrong (timezone is a [neccessary for completeness] attribute of a datetime object, no matter how you represent it).

First, timezone is present (that's what the "Europe/Berlin" is). CEST is not a timezone. CET (interpreted specifically as the winter offset) is not a timezone.

The object DateObject[List[2022, 10, 30, 1, 30, 0], "Instant", "Gregorian", "Europe/Berlin"] is given an unambiguous definition by Mathematica (the moment earlier in time). So there's no lack of rigor here. What's ambiguous is what it means to to say it's 1:30 in the local time when the transition out of daylight saving is happening. This isn't a software ambiguity, it's a real world ambiguity. If I were to say "I'll meet you on the corner at 1:30 am", there are two possible times that I might show up. Let's imagine that you hadn't started with the GMT time and followed that with a TimeZoneConvert, but instead you started with your local Central European time of "1:30 am"...what would you expect Mathematica to do with that? Pause and put up a dialog asking the user to specify which time they meant? If you intended the time to be the later time, the only way to get the TimeZoneConvert back to GMT to work would be to tell Mathematica that you actually meant a different time. You'd have to do some sort of date add of 1 hour. Or you'd just work in GMT from the start. Local time representations simply have no way to disambiguate that hour of time during the transition out of daylight saving. It's up to you do provide that disambiguation, because you're the one that knows what time you're talking about.

I understand that you wish that there was some way to preserve the provenance of the date-time info as you go through TimeZoneConvert conversions. For good or bad, that's just not how it works. You can consider it a bug if you want to, but it's not inherently wrong.

POSTED BY: Eric Rimbey
Posted 3 years ago
POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard