Skip to content

Commit

Permalink
version bump 0.10.2: date processing corner cases
Browse files Browse the repository at this point in the history
- all formats follow cellDates / dateNF (fixes SheetJS#653 h/t @mmancosu)
- IE6-8 Date corrections
- XLML Date force UTC
- updated SSF to 0.9.3 (fixes SheetJS#372 h/t @HuFlungDu)
- removed CFB export
  • Loading branch information
SheetJSDev committed May 17, 2017
1 parent 3fde651 commit 3ff724e
Show file tree
Hide file tree
Showing 24 changed files with 348 additions and 201 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ but not limited to API changes and file location changes. Minor behavioral
changes may not be included if they are not expected to break existing code.


## 0.10.2 (2017-05-??)
## 0.10.2 (2017-05-16)

* CSV generates numeric dates by default (aligning with XLSX cellDates behavior)
* Dates are converted to numbers by default (set `cellDates:true` to emit Dates)
* Module does not export CFB

## 0.9.10 (2017-04-08)

Expand Down
2 changes: 1 addition & 1 deletion bits/01_version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
XLSX.version = '0.10.1';
XLSX.version = '0.10.2';
11 changes: 9 additions & 2 deletions bits/20_jsutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,19 @@ function parse_isodur(s) {
}

var good_pd_date = new Date('2017-02-19T19:06:09.000Z');
if(isNaN(good_pd_date.getFullYear())) good_pd_date = new Date('2/19/17');
var good_pd = good_pd_date.getFullYear() == 2017;
function parseDate(str/*:string|Date*/)/*:Date*/ {
if(good_pd) return new Date(str);
var d = new Date(str);
if(good_pd) return d;
if(str instanceof Date) return str;
if(good_pd_date.getFullYear() == 1917 && !isNaN(d.getFullYear())) {
var s = d.getFullYear();
if(str.indexOf("" + s) > -1) return d;
d.setFullYear(d.getFullYear() + 100); return d;
}
var n = str.match(/\d+/g)||["2017","2","19","0","0","0"];
return new Date(Date.UTC(+n[0], +n[1] - 1, +n[2], +n[3], +n[4], +n[5]));
return new Date(Date.UTC(+n[0], +n[1] - 1, +n[2], (+n[3]||0), (+n[4]||0), (+n[5]||0)));
}

function cc2str(arr/*:Array<number>*/)/*:string*/ {
Expand Down
7 changes: 5 additions & 2 deletions bits/40_harb.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ var SYLK = (function() {
else if(+val === +val) {
val = +val;
if(next_cell_format !== null && SSF.is_date(next_cell_format)) val = numdate(val);
} else if(!isNaN(fuzzydate(val).getDate())) {
val = parseDate(val);
}
arr[R][C] = val;
next_cell_format = null;
Expand All @@ -254,7 +256,7 @@ var SYLK = (function() {
case 'Y':
R = parseInt(record[rj].substr(1))-1; /*C = 0;*/
for(j = arr.length; j <= R; ++j) arr[j] = [];
++F_seen; break;
break;
case 'M': Mval = parseInt(record[rj].substr(1)) / 20; break;
case 'F': break; /* ??? */
case 'P':
Expand All @@ -281,7 +283,7 @@ var SYLK = (function() {
break;
default: if(opts && opts.WTF) throw new Error("SYLK bad record " + rstr);
}
if(F_seen < 2) next_cell_format = null; break;
if(F_seen < 1) next_cell_format = null; break;
default: if(opts && opts.WTF) throw new Error("SYLK bad record " + rstr);
}
}
Expand Down Expand Up @@ -480,6 +482,7 @@ var PRN = (function() {
else if(data === 'FALSE') arr[R][C] = false;
else if(data === ""){/* empty */}
else if(+data == +data) arr[R][C] = +data;
else if(!isNaN(fuzzydate(data).getDate())) arr[R][C] = parseDate(data);
else arr[R][C] = data;
}

Expand Down
8 changes: 6 additions & 2 deletions bits/41_lotus.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ var WK_ = (function() {
case 0x0E: /* NUMBER */
case 0x10: /* FORMULA */
case 0x33: /* STRING */
/* TODO: actual translation of the format code */
if(RT == 0x0E && (val[2] & 0x70) == 0x70 && (val[2] & 0x0F) > 1 && (val[2] & 0x0F) < 15) {
val[1].z = o.dateNF || SSF._table[14];
if(o.cellDates) { val[1].t = 'd'; val[1].v = numdate(val[1].v); }
}
if(o.dense) {
if(!s[val[0].r]) s[val[0].r] = [];
s[val[0].r][val[0].c] = val[1];
} else s[encode_cell(val[0])] = val[1];
/* TODO: FORMAT */
break;
} else switch(RT) {
case 0x16: /* LABEL16 */
Expand Down Expand Up @@ -224,7 +228,7 @@ var WK_ = (function() {
var WK1Enum = {
/*::[*/0x0000/*::]*/: { n:"BOF", f:parseuint16 },
/*::[*/0x0001/*::]*/: { n:"EOF", f:parsenoop },
/*::[*/0x0002/*::]*/: { n: "CALCMODE", f:parsenoop },
/*::[*/0x0002/*::]*/: { n:"CALCMODE", f:parsenoop },
/*::[*/0x0003/*::]*/: { n:"CALCORDER", f:parsenoop },
/*::[*/0x0004/*::]*/: { n:"SPLIT", f:parsenoop },
/*::[*/0x0005/*::]*/: { n:"SYNC", f:parsenoop },
Expand Down
1 change: 1 addition & 0 deletions bits/75_xlml.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function parse_xlml_data(xml, ss, data, cell/*:any*/, base, styles, csty, row, a
cell.v = xml.indexOf("<") > -1 ? unescapexml(ss) : cell.r;
break;
case 'DateTime':
if(xml.slice(-1) != "Z") xml += "Z";
cell.v = (parseDate(xml) - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000);
if(cell.v !== cell.v) cell.v = unescapexml(xml);
else if(cell.v<60) cell.v = cell.v -1;
Expand Down
15 changes: 11 additions & 4 deletions bits/79_html.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* TODO: in browser attach to DOM; in node use an html parser */
/* note: browser DOM element cannot see mso- style attrs, must parse */
var HTML_ = (function() {
function html_to_sheet(str/*:string*/, _opts)/*:Workbook*/ {
var opts = _opts || {};
Expand Down Expand Up @@ -112,16 +112,23 @@ function parse_dom_table(table/*:HTMLElement*/, _opts/*:?any*/)/*:Worksheet*/ {
var row = rows[R];
var elts = row.children;
for(_C = C = 0; _C < elts.length; ++_C) {
var elt = elts[_C], v = elts[_C].innerText;
var elt = elts[_C], v = elts[_C].innerText || elts[_C].textContent;
for(midx = 0; midx < merges.length; ++midx) {
var m = merges[midx];
if(m.s.c == C && m.s.r <= R && R <= m.e.r) { C = m.e.c+1; midx = -1; }
}
/* TODO: figure out how to extract nonstandard mso- style */
CS = +elt.getAttribute("colspan") || 1;
if((RS = +elt.getAttribute("rowspan"))>0 || CS>1) merges.push({s:{r:R,c:C},e:{r:R + (RS||1) - 1, c:C + CS - 1}});
var o = {t:'s', v:v};
if(v != null && v.length && !isNaN(Number(v))) o = {t:'n', v:Number(v)};
var o/*:Cell*/ = {t:'s', v:v};
if(v != null && v.length) {
if(!isNaN(Number(v))) o = {t:'n', v:Number(v)};
else if(!isNaN(fuzzydate(v).getDate())) {
o = ({t:'d', v:parseDate(v)}/*:any*/);
if(!opts.cellDates) o = ({t:'n', v:datenum(o.v)}/*:any*/);
o.z = opts.dateNF || SSF._table[14];
}
}
if(opts.dense) { if(!ws[R]) ws[R] = []; ws[R][C] = o; }
else ws[encode_cell({c:C, r:R})] = o;
if(range.e.c < C) range.e.c = C;
Expand Down
11 changes: 9 additions & 2 deletions bits/90_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ function sheet_to_formulae(sheet/*:Worksheet*/)/*:Array<string>*/ {
function json_to_sheet(js/*:Array<any>*/, opts)/*:Worksheet*/ {
var o = opts || {};
var ws = ({}/*:any*/);
var cell/*:Cell*/;
var range/*:Range*/ = ({s: {c:0, r:0}, e: {c:0, r:js.length}}/*:any*/);
var hdr = o.header || [], C = 0;

Expand All @@ -177,11 +178,17 @@ function json_to_sheet(js/*:Array<any>*/, opts)/*:Worksheet*/ {
if((C=hdr.indexOf(k)) == -1) hdr[C=hdr.length] = k;
var v = js[R][k];
var t = 'z';
var z = "";
if(typeof v == 'number') t = 'n';
else if(typeof v == 'boolean') t = 'b';
else if(typeof v == 'string') t = 's';
else if(v instanceof Date) t = 'd';
ws[encode_cell({c:C,r:R+1})] = {t:t, v:v};
else if(v instanceof Date) {
t = 'd';
if(!o.cellDates) { t = 'n'; v = datenum(v); }
z = o.dateNF || SSF._table[14];
}
ws[encode_cell({c:C,r:R+1})] = cell = ({t:t, v:v}/*:any*/);
if(z) cell.z = z;
});
}
range.e.c = hdr.length - 1;
Expand Down
1 change: 0 additions & 1 deletion bits/98_exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ XLSX.writeFile = writeFileSync;
XLSX.writeFileSync = writeFileSync;
XLSX.writeFileAsync = writeFileAsync;
XLSX.utils = utils;
XLSX.CFB = CFB;
XLSX.SSF = SSF;
4 changes: 2 additions & 2 deletions dist/jszip.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/js
JSZip uses the library pako released under the MIT license :
https://github.com/nodeca/pako/blob/master/LICENSE
*/
!function(e){
(function(e){
if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();
else if("function"==typeof define&&define.amd){JSZip=e();define([],e);}
else{
Expand Down Expand Up @@ -8985,4 +8985,4 @@ function ZStream() {
module.exports = ZStream;
},{}]},{},[9])
(9)
});
}));
34 changes: 17 additions & 17 deletions dist/xlsx.core.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/xlsx.core.min.map

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions dist/xlsx.full.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/xlsx.full.min.map

Large diffs are not rendered by default.

Loading

0 comments on commit 3ff724e

Please sign in to comment.