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

23
  • 3
    For what it's worth, it's not a "minimum value" issue. JS should be able to handle these dates. I can also reproduce these results.
    – Cerbrus
    Commented Sep 3, 2018 at 14:45
  • 2
    @PraveenKumarPurushothaman: Timezone shouldn't affect the minutes.
    – Cerbrus
    Commented Sep 3, 2018 at 14:57
  • 1
    @KonstantinDinev I am convinced that it's not because of DST. There's something else happening that changes the time-zone! shocked Commented Sep 3, 2018 at 15:02
  • 4
    Are we all using Google Chrome? It looks like this is related: chromium tracker and SO post. I tried your examples in Chrome -- same differing results. Firefox: expected results.
    – thmsdnnr
    Commented Sep 3, 2018 at 15:11
  • 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
    Commented Sep 4, 2018 at 13:19

1 Answer 1

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

5
  • 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. Commented Sep 3, 2018 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: en.wikipedia.org/wiki/Eastern_European_Time
    – Nadya
    Commented Sep 3, 2018 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: en.wikipedia.org/wiki/…
    – Nadya
    Commented Sep 3, 2018 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
    Commented Sep 3, 2018 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! Commented Sep 4, 2018 at 7:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.