10

I have an application which allows users to pick some time slots. By default the timeslots are empty, and my .NET back-end has default generated values of type DateTimeOffset, which by default are set to "0001-01-01T00:00:00+00:00".

Now, when I populate a date on the front-end with this value, it generates a date in the local time zone, but with wrong minutes and seconds. This happens only in Chrome. I'm not seeing this under Edge or Firefox.

console.log(new Date("2001-01-01T00:00:00+00:00").toString())
// Mon Jan 01 2001 02:00:00 GMT+0200 (Eastern European Standard Time)
console.log(new Date("1001-01-01T00:00:00+00:00").toString())
//Thu Jan 01 1001 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1801-01-01T00:00:00+00:00").toString())
//Thu Jan 01 1801 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1901-01-01T00:00:00+00:00").toString())
//Tue Jan 01 1901 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1961-01-01T00:00:00+00:00").toString())
//Sun Jan 01 1961 03:00:00 GMT+0300 (Eastern European Standard Time)
console.log(new Date("1921-01-01T00:00:00+00:00").toString())
//Sat Jan 01 1921 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1931-01-01T00:00:00+00:00").toString())
//Thu Jan 01 1931 03:00:00 GMT+0300 (Eastern European Standard Time)
console.log(new Date("1922-01-01T00:00:00+00:00").toString())
//Sun Jan 01 1922 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1923-01-01T00:00:00+00:00").toString())
//Mon Jan 01 1923 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1924-01-01T00:00:00+00:00").toString())
//Tue Jan 01 1924 02:02:04 GMT+0202 (Eastern European Standard Time)
console.log(new Date("1925-01-01T00:00:00+00:00").toString())
//Thu Jan 01 1925 02:00:00 GMT+0200 (Eastern European Standard Time)

As you can see, I played around with the date, to see before which date this happens, but the problem may not be the year 1925, just certain time before the current date. Does anyone know why this is happening?

Screenshot as requested enter image description here

Konstantin Dinev
  • 34,219
  • 14
  • 75
  • 100
  • `new Date("2001-01-01T00:00:00+00:00")` gives me `Mon Jan 01 2001 00:00:00 GMT+0000 (Greenwich Mean Time)`. And `new Date("1923-01-01T00:00:00+00:00")` gives me `Mon Jan 01 1923 00:00:00 GMT+0000 (Greenwich Mean Time)`. Looks fine to me. Check your time-zone. Your local time-zone is the problem here, AFAIK. Did you see that you have a time-zone set that's different? – Praveen Kumar Purushothaman Sep 03 '18 at 14:40
  • Hmm, could be daylight savings issue. Still worth to know why it's happening, cause as you can see the results I get are with wrong minutes and seconds. – Konstantin Dinev Sep 03 '18 at 14:42
  • Even DST doesn't affect minutes level. I cannot replicate the issue at all. All I can see is the hours are different in my system. – Praveen Kumar Purushothaman Sep 03 '18 at 14:43
  • Can you please post a [mcve] to demonstrate the issue? A screenshot will be really helpful. – Praveen Kumar Purushothaman Sep 03 '18 at 14:44
  • 3
    For what it's worth, it's not a ["minimum value"](https://stackoverflow.com/questions/11526504/minimum-and-maximum-date) issue. JS should be able to handle these dates. I can also [reproduce](https://i.stack.imgur.com/HL2Tw.png) these results. – Cerbrus Sep 03 '18 at 14:45
  • Thank you @Cerbrus. As for the minimal, complete and verifiable answer, I'm not new to SO, as you can see, but I'm updating the question with a screenshot. JS doesn't allow to create dates in different time zone than the local one, so I can't show what happens if I'm in a different time zone. – Konstantin Dinev Sep 03 '18 at 14:48
  • Woah... @Cerbrus May be because of the time-zone you live in? I am in the UK (GMT+0100), so? – Praveen Kumar Purushothaman Sep 03 '18 at 14:52
  • 2
    @PraveenKumarPurushothaman: Timezone shouldn't affect the minutes. – Cerbrus Sep 03 '18 at 14:57
  • @Cerbrus Did you both notice the time-zone offset? What does **GMT+0019** mean? 0:19 hours? – Praveen Kumar Purushothaman Sep 03 '18 at 15:00
  • @PraveenKumarPurushothaman I did. It's +0202 for me, but only if the date is before the threshold, which is still weird. I'm starting to believe more that it has to do with daylight savings somehow... And the offset still doesn't quite explain the 4 seconds it's adding in my case. – Konstantin Dinev Sep 03 '18 at 15:01
  • 1
    @KonstantinDinev I am convinced that it's not because of DST. There's something else happening that changes the time-zone! *shocked* – Praveen Kumar Purushothaman Sep 03 '18 at 15:02
  • Wait... Why am I not getting affected by this bug or feature? – Praveen Kumar Purushothaman Sep 03 '18 at 15:04
  • Maybe because you're on Greenwich time. – Konstantin Dinev Sep 03 '18 at 15:09
  • Yea, but not convincing... `0019` and `0202` aren't even valid time-zone offsets... – Praveen Kumar Purushothaman Sep 03 '18 at 15:10
  • 4
    Are we all using Google Chrome? It looks like this is related: [chromium tracker](https://chromium-review.googlesource.com/c/v8/v8/+/572148) and [SO post](https://stackoverflow.com/a/51008329/7316502). I tried your examples in Chrome -- same differing results. Firefox: expected results. – thmsdnnr Sep 03 '18 at 15:11
  • I see the expected results in Edge as well. – Heretic Monkey Sep 03 '18 at 15:17
  • @thmsdnnr Ahhh... Yes... I am using Chrome too... `:D` – Praveen Kumar Purushothaman Sep 03 '18 at 15:19
  • Seems to be related to [Browsers, time zones, Chrome 67 Error](https://stackoverflow.com/questions/50609860/browsers-time-zones-chrome-67-error) – samabcde Sep 03 '18 at 15:22
  • @thmsdnnr I guess we have an answer then. It's a chrome issue. I just verified that I'm not seeing the same thing in edge. I will update the question with this information. – Konstantin Dinev Sep 03 '18 at 15:23
  • Seriously @RobG! You have a gold Date badge? `:o` – Praveen Kumar Purushothaman Sep 04 '18 at 08:18
  • @PraveenKumarPurushothaman—not sure I understand your comment, I don't pay any attention to badges. – RobG Sep 04 '18 at 09:53
  • @RobG That's alright... But surprised to see a person who has answered a lot of `date` questions... `:D` – Praveen Kumar Purushothaman Sep 04 '18 at 12:43
  • 2
    @PraveenKumarPurushothaman—Ok. :-) Most Date questions are poorly answered. For such a simple object, it's sorely misunderstood and in serious, serious need of updating with something better. – RobG Sep 04 '18 at 13:19

1 Answers1

7

Prior to 1883 Time Zones were not standardized. If you check every year you'll notice that 1883 is "broken" with the additional minutes and 1884 is "fine". Chrome handles this transition very well - you'll notice the "problem" doesn't exist in Firefox.

new Date("1883-01-01T00:00:00+00:00")
Sun Dec 31 1882 16:07:02 GMT-0752 (Pacific Standard Time)
new Date("1884-01-01T00:00:00+00:00")
Mon Dec 31 1883 16:00:00 GMT-0800 (Pacific Standard Time)

In fact, you can track this down to November 18th, 1883.

new Date("1883-11-18T00:00:00+00:00")
Sat Nov 17 1883 16:07:02 GMT-0752 (Pacific Standard Time)
new Date("1883-11-19T00:00:00+00:00")
Sun Nov 18 1883 16:00:00 GMT-0800 (Pacific Standard Time)

Chrome tries very hard to match time, even going so far as to calculate the suspended DST of Ramadan in Egypt in 2010.

Read more here: https://www.huffingtonpost.com/quora/how-when-and-why-were-tim_b_5838042.html

Nadya
  • 96
  • 1
  • 6
  • Just one note. It seems like the date before which this happens is different for every system. I tried it with my colleague at work, and it's a different result than the one that I'm getting. – Konstantin Dinev Sep 03 '18 at 15:32
  • @KonstantinDinev It's going to depend on when your local timezone adopted 'standardized time'. In some parts of the UK this should be in 1840, in others it will be in 1847. Ireland wouldn't get it until 1916. I'm not familiar enough with how many edge cases Chrome tries to catch for these, but I imagine they try hard to catch most of them. :) For myself here in the US, it was November 18th, 1884. OP is in Eastern Europe: https://en.wikipedia.org/wiki/Eastern_European_Time – Nadya Sep 03 '18 at 15:37
  • 2
    Upon some further investigation on Eastern Europe "GMT Adoption Years" I discovered that prior to 1925, Chrome might be reporting GMAT instead of GMT: https://en.wikipedia.org/wiki/Greenwich_Mean_Time#Ambiguity_in_the_definition_of_GMT – Nadya Sep 03 '18 at 15:42
  • 1
    Worth pointing out that "standardised" here doesn't mean there is a standards body that determines the timezone offset for a place, it's really just an agreement that places will use multiples of 30 minutes for their offset. Places adopt a timezone offset that suits them, e.g. Kiribati went from -10/-11 to +14/+13 in 1995 (maybe they wanted to be the first place on Earth to see sunrise, rather than last). Broken Hill is in New South Wales, which is +10/+11 but because it's so far west, uses the South Australian timezone of +0930/+1030. :-) – RobG Sep 03 '18 at 22:25
  • 1
    @Nadya The first wiki says that standardized time is adopted in Bulgaria since 1894, but I'm getting the wrong results up until 1925, so the reason must be the GMT adoption over GMAT in your second link. Thanks all for the useful information! – Konstantin Dinev Sep 04 '18 at 07:52