Compare commits

...

6 Commits

Author SHA1 Message Date
Ivan Trusov
b1c5037ca8 Refactor OADate handling 2022-06-02 13:28:52 +03:00
Ivan Trusov
51d05ad8a0 Merge remote-tracking branch 'origin/fix-basedate' into fix-basedate
# Conflicts:
#	xlsx.js
2022-06-01 09:25:09 +03:00
Ivan Trusov
db81ca6594 Fix basedate calculation
Co-authored-by: Philippe Rivière <fil@rezo.net>
2022-06-01 09:24:10 +03:00
Ivan Trusov
64e8998e59 Fix basedate calculation
Correct numdate / datenum calculation to eliminate problems
with timezones that equal nowadays but were different
in the past (e.g. Europe/Minsk and Europe/Moscow)
2022-06-01 09:23:41 +03:00
Ivan Trusov
1dfabe74b1
Fix basedate calculation
Co-authored-by: Philippe Rivière <fil@rezo.net>
2022-05-31 17:26:54 +03:00
Ivan Trusov
c14e1712ea Fix basedate calculation
Correct numdate / datenum calculation to eliminate problems
with timezones that equal nowadays but were different
in the past (e.g. Europe/Minsk and Europe/Moscow)
2022-05-13 11:00:36 +03:00

25
xlsx.js generated

@ -3213,22 +3213,21 @@ function evert_arr(obj) {
return o;
}
var basedate = new Date(1899, 11, 30, 0, 0, 0); // 2209161600000
var base1900 = Date.UTC(1899, 11, 30);
var base1904 = Date.UTC(1904, 0, 1);
// According to https://docs.microsoft.com/ru-ru/archive/blogs/ericlippert/erics-complete-guide-to-vt_date
// we must treat OLE Automation Date as it has no timezone at all.
// So to avoid any possible TZ/DST issues do calculations in UTC
function datenum(v, date1904) {
var epoch = v.getTime();
if(date1904) epoch -= 1462*24*60*60*1000;
var dnthresh = basedate.getTime() + (v.getTimezoneOffset() - basedate.getTimezoneOffset()) * 60000;
return (epoch - dnthresh) / (24 * 60 * 60 * 1000);
var start = date1904 ? base1904 : base1900;
var vTime = Date.UTC(v.getFullYear(), v.getMonth(), v.getDate(), v.getHours(), v.getMinutes(), v.getSeconds(), v.getMilliseconds());
return (vTime - start) / 86400000;
}
var refdate = new Date();
var dnthresh = basedate.getTime() + (refdate.getTimezoneOffset() - basedate.getTimezoneOffset()) * 60000;
var refoffset = refdate.getTimezoneOffset();
function numdate(v) {
var out = new Date();
out.setTime(v * 24 * 60 * 60 * 1000 + dnthresh);
if (out.getTimezoneOffset() !== refoffset) {
out.setTime(out.getTime() + (out.getTimezoneOffset() - refoffset) * 60000);
}
var out = new Date(base1900 + v * 86400000);
// De-adjust timezone offset
out.setTime(out.getTime() + out.getTimezoneOffset() * 60000);
return out;
}