I am trying to calculate the difference between two dates that are apart over 600 years.
I suspected it has something to do with leap seconds, but upon closer inspection, there is something even weirder going on. The extra 02:16
minutes are changed all at once between these two dates.
PS: My local timezone is UTC+1
new Date(1891, 8, 30)
// Wed Sep 30 1891 00:00:00 GMT+0057 (Central European Summer Time) <- this is weird
new Date(1891, 9, 1)
// Thu Oct 01 1891 00:02:16 GMT+0100 (Central European Summer Time) <- this is weird
new Date(1891, 9, 2)
// Fri Oct 02 1891 00:00:00 GMT+0100 (Central European Summer Time)
or
new Date(Date.UTC(1891, 8, 30, 23, 2, 15))
// Wed Sep 30 1891 23:59:59 GMT+0057 (Central European Summer Time)
new Date(Date.UTC(1891, 8, 30, 23, 2, 16))
// Thu Oct 01 1891 00:02:16 GMT+0100 (Central European Summer Time)
So ultimately I wanted to display n-th
ongoing hour after d0
(below) and I was unexpectedly getting lagging hour that switched at 02:17
mark of a real hour.
I used something along these lines
let HR = 60 * 60 * 1000 // 3600000 ... one hour in milliseconds
let d0 = new Date(1358, 7, 14) // 14.8. 1358
let d1 = new Date(2011, 3, 17) // "today"
let dt = d1 - d0
let r = Math.ceil(dt / HR) // because I want to switch the hour as soon as first millisecond of that hour passes
But little did I know that dt / HR
is actually not a whole hour but 5721214.962222222
, whereas at this point of time I have already expected 5721215
.
let something = dt % HR / 1000 / 60 // 57.73333333 minutes
In the end I worked around it with using Date.UTC
and the respective getUTC...
methods for all calculations, but I would still like to know more about this.