From 097f026d0345dbff53338493913aba0c6a656386 Mon Sep 17 00:00:00 2001 From: SheetJS Date: Tue, 24 Jun 2014 20:07:30 -0400 Subject: [PATCH] version bump 0.8.1: more weird formats - handle formats like ???00.00 - return empty string with bad dates under A/P and AM/PM formats --- .gitignore | 5 +++++ README.md | 2 +- package.json | 2 +- ssf.js | 10 +++++----- ssf.md | 13 ++++++------- 5 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1a35068 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +node_modules/ +tmp/ +.vocrc +v8.log +perf.log diff --git a/README.md b/README.md index a1e7de3..c6c6b4f 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Apache 2.0 ## Tests -[![Build Status](https://travis-ci.org/SheetJS/ssf.png?branch=master)](https://travis-ci.org/SheetJS/ssf) +[![Build Status](https://travis-ci.org/SheetJS/ssf.svg?branch=master)](https://travis-ci.org/SheetJS/ssf) [![Coverage Status](https://coveralls.io/repos/SheetJS/ssf/badge.png?branch=master)](https://coveralls.io/r/SheetJS/ssf?branch=master) diff --git a/package.json b/package.json index 4cc1431..afee4ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ssf", - "version": "0.8.0", + "version": "0.8.1", "author": "SheetJS", "description": "Format data using ECMA-376 spreadsheet Format Codes", "keywords": [ "format", "sprintf", "spreadsheet" ], diff --git a/ssf.js b/ssf.js index 39e7751..84125f0 100644 --- a/ssf.js +++ b/ssf.js @@ -2,7 +2,7 @@ /*jshint -W041 */ var SSF = {}; var make_ssf = function make_ssf(SSF){ -SSF.version = '0.8.0'; +SSF.version = '0.8.1'; function _strrev(x) { var o = "", i = x.length-1; while(i>=0) o += x.charAt(i--); return o; } function fill(c,l) { var o = ""; while(o.length < l) o+=c; return o; } function pad0(v,d){var t=""+v; return t.length>=d?t:fill('0',d-t.length)+t;} @@ -375,7 +375,7 @@ function write_num_flt(type, fmt, val) { if(fmt.length <= o.length) return o; return hashq(fmt.substr(0,fmt.length-o.length)) + o; } - if((r = fmt.match(/^([#0]+)\.([#0]+)$/)) !== null) { + if((r = fmt.match(/^([#0?]+)\.([#0]+)$/)) !== null) { o = "" + val.toFixed(Math.min(r[2].length,10)).replace(/([^0])0+$/,"$1"); ri = o.indexOf("."); var lres = fmt.indexOf(".") - ri, rres = fmt.length - o.length - lres; @@ -539,7 +539,7 @@ function eval_fmt(fmt, v, opts, flen) { out[out.length] = {t:'T', v:v}; ++i; break; case 'B': case 'b': if(fmt[i+1] === "1" || fmt[i+1] === "2") { - if(dt == null) dt = parse_date_code(v, opts, fmt[i+1] === "2"); + if(dt==null) { dt=parse_date_code(v, opts, fmt[i+1] === "2"); if(dt==null) return ""; } out[out.length] = {t:'X', v:fmt.substr(i,2)}; lst = c; i+=2; break; } /* falls through */ @@ -556,8 +556,8 @@ function eval_fmt(fmt, v, opts, flen) { case 'A': q={t:c, v:"A"}; if(dt==null) dt=parse_date_code(v, opts); - if(fmt.substr(i, 3) === "A/P") {q.v = dt.H >= 12 ? "P" : "A"; q.t = 'T'; hr='h';i+=3;} - else if(fmt.substr(i,5) === "AM/PM") { q.v = dt.H >= 12 ? "PM" : "AM"; q.t = 'T'; i+=5; hr='h'; } + if(fmt.substr(i, 3) === "A/P") { if(dt!=null) q.v = dt.H >= 12 ? "P" : "A"; q.t = 'T'; hr='h';i+=3;} + else if(fmt.substr(i,5) === "AM/PM") { if(dt!=null) q.v = dt.H >= 12 ? "PM" : "AM"; q.t = 'T'; i+=5; hr='h'; } else { q.t = "t"; ++i; } if(dt==null && q.t === 'T') return ""; out[out.length] = q; lst = c; break; diff --git a/ssf.md b/ssf.md index 39096f3..2c14a0f 100644 --- a/ssf.md +++ b/ssf.md @@ -669,7 +669,7 @@ The general class `/^[#0?]+$/` treats the '0' as literal, '#' as noop, '?' as sp if(fmt.length <= o.length) return o; return hashq(fmt.substr(0,fmt.length-o.length)) + o; } - if((r = fmt.match(/^([#0]+)\.([#0]+)$/)) !== null) { + if((r = fmt.match(/^([#0?]+)\.([#0]+)$/)) !== null) { o = "" + val.toFixed(Math.min(r[2].length,10)).replace(/([^0])0+$/,"$1"); ri = o.indexOf("."); var lres = fmt.indexOf(".") - ri, rres = fmt.length - o.length - lres; @@ -881,7 +881,7 @@ acts just like `y` except the year is shifted: ``` case 'B': case 'b': if(fmt[i+1] === "1" || fmt[i+1] === "2") { - if(dt == null) dt = parse_date_code(v, opts, fmt[i+1] === "2"); + if(dt==null) { dt=parse_date_code(v, opts, fmt[i+1] === "2"); if(dt==null) return ""; } out[out.length] = {t:'X', v:fmt.substr(i,2)}; lst = c; i+=2; break; } /* falls through */ @@ -930,8 +930,8 @@ the HH/hh jazz. TODO: investigate this further. case 'A': q={t:c, v:"A"}; if(dt==null) dt=parse_date_code(v, opts); - if(fmt.substr(i, 3) === "A/P") {q.v = dt.H >= 12 ? "P" : "A"; q.t = 'T'; hr='h';i+=3;} - else if(fmt.substr(i,5) === "AM/PM") { q.v = dt.H >= 12 ? "PM" : "AM"; q.t = 'T'; i+=5; hr='h'; } + if(fmt.substr(i, 3) === "A/P") { if(dt!=null) q.v = dt.H >= 12 ? "P" : "A"; q.t = 'T'; hr='h';i+=3;} + else if(fmt.substr(i,5) === "AM/PM") { if(dt!=null) q.v = dt.H >= 12 ? "PM" : "AM"; q.t = 'T'; i+=5; hr='h'; } else { q.t = "t"; ++i; } if(dt==null && q.t === 'T') return ""; out[out.length] = q; lst = c; break; @@ -1487,9 +1487,8 @@ cat tmp/*.js > ssf.js ``` ```>.gitignore -.gitignore -tmp/ node_modules/ +tmp/ .vocrc v8.log perf.log @@ -1557,7 +1556,7 @@ coveralls: ```json>package.json { "name": "ssf", - "version": "0.8.0", + "version": "0.8.1", "author": "SheetJS", "description": "Format data using ECMA-376 spreadsheet Format Codes", "keywords": [ "format", "sprintf", "spreadsheet" ],