Skip to content

Commit fdbbf2d

Browse files
committed
precise time parse (h/t @Ragearino @MyAddonsDev )
1 parent c02eb14 commit fdbbf2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+414
-1479
lines changed

bits/20_jsutils.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,22 @@ function fuzzynum(s/*:string*/)/*:number*/ {
159159
}
160160

161161
/* NOTE: Chrome rejects bare times like 1:23 PM */
162-
var FDRE1 = /^(0?\d|1[0-2])(?:|:([0-5]?\d)(?:|(\.\d+)(?:|:([0-5]?\d))|:([0-5]?\d)(|\.\d+)))([ap])m?/;
162+
var FDRE1 = /^(0?\d|1[0-2])(?:|:([0-5]?\d)(?:|(\.\d+)(?:|:([0-5]?\d))|:([0-5]?\d)(|\.\d+)))\s+([ap])m?$/;
163163

164164
function fuzzytime1(M) /*:Date*/ {
165-
/* TODO: 1904 adjustment */
166-
if(!M[2]) return new Date(1900,0,0,(+M[1]%12) + (M[7] == "p" ? 12 : 0), 0, 0, 0);
165+
/* TODO: 1904 adjustment, keep in sync with base date */
166+
if(!M[2]) return new Date(1899,11,30,(+M[1]%12) + (M[7] == "p" ? 12 : 0), 0, 0, 0);
167167
if(M[3]) {
168-
if(M[4]) return new Date(1900,0,0,(+M[1]%12) + (M[7] == "p" ? 12 : 0), +M[2], +M[4], parseFloat(M[3])*1000);
169-
else return new Date(1900,0,0,(M[7] == "p" ? 12 : 0), +M[1], +M[2], parseFloat(M[3])*1000);
168+
if(M[4]) return new Date(1899,11,30,(+M[1]%12) + (M[7] == "p" ? 12 : 0), +M[2], +M[4], parseFloat(M[3])*1000);
169+
else return new Date(1899,11,30,(M[7] == "p" ? 12 : 0), +M[1], +M[2], parseFloat(M[3])*1000);
170170
}
171-
else if(M[5]) return new Date(1900, 0, 0, (+M[1]%12) + (M[7] == "p" ? 12 : 0), +M[2], +M[5], M[6] ? parseFloat(M[6]) * 1000 : 0);
172-
else return new Date(1900,0,0,(+M[1]%12) + (M[7] == "p" ? 12 : 0), +M[2], 0, 0);
171+
else if(M[5]) return new Date(1899,11,30, (+M[1]%12) + (M[7] == "p" ? 12 : 0), +M[2], +M[5], M[6] ? parseFloat(M[6]) * 1000 : 0);
172+
else return new Date(1899,11,30,(+M[1]%12) + (M[7] == "p" ? 12 : 0), +M[2], 0, 0);
173173
}
174174
var lower_months = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
175175
function fuzzydate(s/*:string*/)/*:Date*/ {
176176
var lower = s.toLowerCase();
177-
var lnos = lower.replace(/\s+/g, "");
177+
var lnos = lower.replace(/\s+/g, " ").trim();
178178
var M = lnos.match(FDRE1);
179179
if(M) return fuzzytime1(M);
180180

bits/40_harb.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -960,12 +960,12 @@ var PRN = /*#__PURE__*/(function() {
960960
else if(s == "TRUE") { cell.t = 'b'; cell.v = true; }
961961
else if(s == "FALSE") { cell.t = 'b'; cell.v = false; }
962962
else if(!isNaN(v = fuzzynum(s))) { cell.t = 'n'; if(o.cellText !== false) cell.w = s; cell.v = v; }
963-
else if(!isNaN(fuzzydate(s).getDate()) || _re && s.match(_re)) {
963+
else if(!isNaN((v = fuzzydate(s)).getDate()) || _re && s.match(_re)) {
964964
cell.z = o.dateNF || table_fmt[14];
965965
var k = 0;
966-
if(_re && s.match(_re)){ s=dateNF_fix(s, o.dateNF, (s.match(_re)||[])); k=1; }
967-
if(o.cellDates) { cell.t = 'd'; cell.v = parseDate(s, k); }
968-
else { cell.t = 'n'; cell.v = datenum(parseDate(s, k)); }
966+
if(_re && s.match(_re)){ s=dateNF_fix(s, o.dateNF, (s.match(_re)||[])); k=1; v = parseDate(s, k); }
967+
if(o.cellDates) { cell.t = 'd'; cell.v = v; }
968+
else { cell.t = 'n'; cell.v = datenum(v); }
969969
if(o.cellText !== false) cell.w = SSF_format(cell.z, cell.v instanceof Date ? datenum(cell.v):cell.v);
970970
if(!o.cellNF) delete cell.z;
971971
} else {

demos/README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ can be installed with Bash on Windows or with `cygwin`.
1818
### Included Demos
1919

2020
**JavaScript APIs**
21-
- [`XMLHttpRequest and fetch`](xhr/)
21+
- [`XMLHttpRequest and fetch`](https://docs.sheetjs.com/docs/getting-started/demos/network)
2222
- [`Clipboard Data`](https://docs.sheetjs.com/docs/getting-started/demos/clipboard)
2323
- [`Typed Arrays for Machine Learning`](https://docs.sheetjs.com/docs/getting-started/demos/ml)
2424
- [`LocalStorage and SessionStorage`](https://docs.sheetjs.com/docs/getting-started/demos/database#localstorage-and-sessionstorage)
@@ -29,7 +29,6 @@ can be installed with Bash on Windows or with `cygwin`.
2929
- [`Angular.JS`](https://docs.sheetjs.com/docs/getting-started/demos/legacy#angularjs)
3030
- [`Angular 2+ and Ionic`](angular2/)
3131
- [`Knockout`](https://docs.sheetjs.com/docs/getting-started/demos/legacy#knockoutjs)
32-
- [`Meteor`](meteor/)
3332
- [`React, React Native and NextJS`](react/)
3433
- [`VueJS, WeeX and NuxtJS`](vue/)
3534

@@ -43,8 +42,7 @@ can be installed with Bash on Windows or with `cygwin`.
4342
**Platforms and Integrations**
4443
- [`Command-Line Tools`](https://docs.sheetjs.com/docs/getting-started/demos/cli)
4544
- [`NodeJS Server-Side Processing`](server/)
46-
- [`Deno`](deno/)
47-
- [`Electron`](electron/)
45+
- [`Electron`](https://docs.sheetjs.com/docs/getting-started/demos/desktop#electron)
4846
- [`NW.js`](https://docs.sheetjs.com/docs/getting-started/demos/desktop#nwjs)
4947
- [`Chrome / Chromium Extension`](https://docs.sheetjs.com/docs/getting-started/demos/chromium)
5048
- [`Google Sheets API`](https://docs.sheetjs.com/docs/getting-started/demos/gsheet)
@@ -68,7 +66,7 @@ can be installed with Bash on Windows or with `cygwin`.
6866
- [`rollup`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#rollup)
6967
- [`snowpack`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#snowpack)
7068
- [`swc`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#swc)
71-
- [`systemjs`](systemjs/)
69+
- [`systemjs`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#systemjs)
7270
- [`vite`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#vite)
7371
- [`webpack 2.x`](webpack/)
7472
- [`wmr`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#wmr)

demos/electron/Makefile

Lines changed: 0 additions & 15 deletions
This file was deleted.

demos/electron/README.md

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,6 @@
11
# Electron
22

3-
This library is compatible with Electron and should just work out of the box.
4-
The demonstration uses Electron 18.2.0. The library is added via `require` from
5-
the renderer process.
6-
7-
The library can also be required from the main process, as shown in this demo
8-
to render a version string in the About dialog on OSX.
9-
10-
The standard HTML5 `FileReader` techniques from the browser apply to Electron.
11-
This demo includes a drag-and-drop box as well as a file input box, mirroring
12-
the [SheetJS Data Preview Live Demo](http://oss.sheetjs.com/sheetjs/)
13-
14-
The core data in this demo is an editable HTML table. The readers build up the
15-
table using `sheet_to_html` (with `editable:true` option) and the writers scrape
16-
the table using `table_to_book`.
17-
18-
The demo project is structured for `electron-forge`:
19-
- `npm start` will start the app.
20-
- `npm run make` will build a standalone app.
21-
22-
The standalone app was tested on an Intel Mac (`darwin-x64`).
23-
24-
## Reading and Writing Files
25-
26-
Since electron provides an `fs` implementation, `readFile` and `writeFile` can
27-
be used in conjunction with the standard dialog windows. For example:
28-
29-
```js
30-
/* from app code, require('electron').remote calls back to main process */
31-
var dialog = require('electron').remote.dialog;
32-
33-
/* show a file-open dialog and read the first selected file */
34-
var o = dialog.showOpenDialog({ properties: ['openFile'] });
35-
var workbook = XLSX.readFile(o[0]);
36-
37-
/* show a file-save dialog and write the workbook */
38-
var o = dialog.showSaveDialog();
39-
XLSX.writeFile(workbook, o);
40-
```
41-
42-
## Breaking Changes in Electron
43-
44-
The first version of this demo used Electron 1.7.5.
45-
46-
Electron 9.0.0 and later require the preference `nodeIntegration: true` in order
47-
to `require('XLSX')` in the renderer process.
48-
49-
Electron 12.0.0 and later also require `worldSafeExecuteJavascript: true` and
50-
`contextIsolation: true`.
51-
52-
Electron 14+ must use `@electron/remote` instead of `remote`.
53-
54-
3+
[The new demo](https://docs.sheetjs.com/docs/getting-started/demos/desktop#electron)
4+
includes an improved example and detailed explanations.
555

566
[![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-xlsx?pixel)](https://github.com/SheetJS/js-xlsx)

demos/electron/index.html

Lines changed: 0 additions & 39 deletions
This file was deleted.

demos/electron/index.js

Lines changed: 0 additions & 79 deletions
This file was deleted.

demos/electron/main.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

demos/electron/package.json

Lines changed: 0 additions & 51 deletions
This file was deleted.

demos/meteor/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)