Group Abstract Group Abstract

Message Boards Message Boards

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

Daylight saving time - timezone conversion trouble

Posted 2 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 2 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 2 years ago

Your A and B distinctions would be nice, but I'm not aware of any time standard that uses something like that. You could just implement it yourself if it's that important to you. But the fact that Mathematica doesn't use it doesn't constitute a bug.

And it's not a matter of Mathematica not understanding the daylight saving convention. Look at this:

TimeZoneOffset["Europe/Berlin", {2022, 10, 30, 2, 30, 0}]

{2, 1}

So, Mathematica knows that there is ambiguity here.

And if we had your A/B convention, then the user would need to apply that convention when they input date-times directly (as opposed to doing a conversion from GMT). Doesn't seem particularly elegant to me.

Again, it's perfectly reasonable for you to want a date-time framework to keep track of all date-times in some absolute format regardless of timezone conversions or other manipulations. But that's not what Mathematica has chosen to implement. That's not a bug, is a design choice. The more I think about it, the more I think it was the right choice, because otherwise the system would have to try to resolve ambiguities itself without any context. The way it is now in Mathematica, the user, the one with knowledge of which date-times they want to specify, is the one with the responsibility to resolve ambiguities.

POSTED BY: Eric Rimbey
Posted 2 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 2 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 2 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 2 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 2 years ago

If there is a bug here, I'd say that it's just a trivial one with regard to presentation.

Your objection seems to be that Sun 30 Oct 2022 02:30:00CEST is asserting that this time is in "daylight saving time" instead of "standard time". But standard time and daylight saving time aren't attributes of time. They are standards for determining offsets for local time representations. So, in the local time of Berlin (let's say for simplicity), the clocks would indeed read 2:30. The FullForm of that particular date object is

DateObject[List[2022, 10, 30, 2, 30, 0], "Instant", "Gregorian", "Europe/Berlin"]

The notion of "standard" or "daylight saving" is absent (as is day of week). The display of "CEST" (and "Sun") was just a presentation issue, a choice that it made for showing you the data. That attribute had to be derived--it wasn't actually part of the raw data.

You also assert that the conversion back to GMT is a bug. But of course we have a problem here. We don't have a nice one-to-one relationship in our original conversion from GMT to CE(S)T, so the distinction between the second and third times is lost.

Now maybe you'd prefer that a DateTime object should store unix time or something absolute like that and have all other timezone related behaviors be matters of presentation. But that's not how Wolfram did it. I assume that there is a legitimate reason for their choice.

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