forked from sheetjs/sheetjs
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)
This commit is contained in:
parent
83ddb4c120
commit
64e8998e59
9
xlsx.js
generated
9
xlsx.js
generated
@ -3213,16 +3213,19 @@ function evert_arr(obj) {
|
||||
return o;
|
||||
}
|
||||
|
||||
var basedate = new Date(1899, 11, 30, 0, 0, 0); // 2209161600000
|
||||
var basedate = new Date(); // 2209161600000
|
||||
basedate.setUTCFullYear(1899, 11, 30);
|
||||
basedate.setUTCHours(0, 0, 0);
|
||||
|
||||
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;
|
||||
var dnthresh = basedate.getTime() + v.getTimezoneOffset() * 60000;
|
||||
return (epoch - dnthresh) / (24 * 60 * 60 * 1000);
|
||||
}
|
||||
var refdate = new Date();
|
||||
var dnthresh = basedate.getTime() + (refdate.getTimezoneOffset() - basedate.getTimezoneOffset()) * 60000;
|
||||
var refoffset = refdate.getTimezoneOffset();
|
||||
var dnthresh = basedate.getTime() + refoffset * 60000;
|
||||
function numdate(v) {
|
||||
var out = new Date();
|
||||
out.setTime(v * 24 * 60 * 60 * 1000 + dnthresh);
|
||||
|
Loading…
Reference in New Issue
Block a user