1

I'm having a weird situation. Recently I've moved from Azure cloud to Digital Ocean server. I'm using Nodejs version v10.15.0 and Centos 7.

My timedatectl output is

[deploy@prod-ca-api install-scripts]$ timedatectl
Local time: Tue 2019-03-19 15:34:21 IST
Universal time: Tue 2019-03-19 10:04:21 UTC
RTC time: Tue 2019-03-19 10:04:21
Time zone: Asia/Kolkata (IST, +0530)
NTP enabled: no
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
[deploy@prod-ca-api install-scripts]$ 

The output of date by setting the hours to start of the day is giving me proper output for the current date. But the same is responding with 24 minutes difference for dates below the year 1900.

My timezone setting is in IST (+5.30)

[deploy@prod-ca-api install-scripts]$ date
Tue Mar 19 15:36:57 IST 2019
[deploy@prod-ca-api install-scripts]$ node
> let a = new Date()
undefined
> a.setHours(0,0,0,0)
1552933800000
> a
2019-03-18T18:30:00.000Z
> a = new Date('1700-01-01')
1700-01-01T00:00:00.000Z
> a.setHours(0,0,0,0)
-8520357208000
> a
1699-12-31T18:06:32.000Z

Previously in Azure servers, I used to get 1699-12-31T18:30:00.000Z instead of 1699-12-31T18:06:32.000Z

Deepan
  • 13
  • 2
  • Welcome to Super User! I already provided an answer, but it's not an absolute answer. My question to you is: why do you think the 18:30 time is the correct one? – Aulis Ronkainen Mar 19 '19 at 16:36
  • 1
    Previously in Azure servers, I used to get 18:30 and I thought 00:00 - 5:30 for the start of the day gives 18:30 of the previous date. That's why I assumed it as a correct one. – Deepan Mar 20 '19 at 06:08
  • I understand your reasoning for this, but the truth is you should really avoid using pre 1900 dates, because there might be more issues similar to this or even worse. You can't reliably count hours from these dates without implicitly setting the time zones and other localisations. – Aulis Ronkainen Mar 20 '19 at 10:03
  • 1
    Yeah, I better start to avoid those dates. Thanks, man. – Deepan Mar 20 '19 at 12:09

1 Answers1

1

I think that the right time should in fact be 18:06. I made this conclusion after I read this article: https://www.dailyo.in/variety/indian-standard-time-time-zones-bagan-time/story/1/17080.html

Relevant parts of this article are:

Indian Standard Time, which is observed in India and well, not too strangely in neighbouring Sri Lanka where they call it the Sri-Lanka Standard Time, has an offset of UTC+05:30.

This is clear and easy to understand.

India had no official time zone till 1906; we had three presidencies: Bombay, Calcutta, Madras, and three local times for the three cities, depending on where they fell on the longitude. The three time zones, thus created, were followed by all the states or cities around and near it.

This is where it gets interesting. India apparently didn't have official time zone until January 1st 1906. Which is in line with your empirical research.

Calcutta was set at UTC+05.54, making it +00:24 of the current IST.

This would explain the strange behavior in NodeJS (kind of). Again in line with your research.

There is a lot more to this history, but anyway I would conclude that the time could be correct in both of these cases. It's very hard to determine precise time for these old dates, because the whole time zone didn't even exist. In general you shouldn't be trusting old dates, because time zones can be really confusing and countries might have also been using different calendars. Also there are no realistic use cases for using dates in 1600s for example.

Aulis Ronkainen
  • 2,612
  • 42
  • 29
  • 27
  • 1
    Thank you for your detailed research and answer. Kudos Man !!. But I don't understand how Azure gave 18:30 time previously for those dates. – Deepan Mar 20 '19 at 06:12
  • No problem. Yes, I don't understand it either. I was also contemplating this and I don't have the means to find out why it works that way. I assume that it has something to do with the environment. Are the JavaScript versions the same? It is possible that the Azure doesn't take into account that the time zone changes, somehow? – Aulis Ronkainen Mar 20 '19 at 07:59
  • 1
    Your hunch is correct, in Azure servers, my NodeJS version is v8.15.0, in DO I've installed v10.15.0. In NodeJS version 8.15.0 the date is returning with 18:30. On v10.15 its returning 18:06. :) – Deepan Mar 20 '19 at 11:34