Skip to content

Commit

Permalink
precise time parse (h/t @Ragearino @MyAddonsDev )
Browse files Browse the repository at this point in the history
  • Loading branch information
SheetJSDev committed Aug 7, 2022
1 parent c02eb14 commit fdbbf2d
Show file tree
Hide file tree
Showing 51 changed files with 414 additions and 1,479 deletions.
16 changes: 8 additions & 8 deletions bits/20_jsutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,22 @@ function fuzzynum(s/*:string*/)/*:number*/ {
}

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

function fuzzytime1(M) /*:Date*/ {
/* TODO: 1904 adjustment */
if(!M[2]) return new Date(1900,0,0,(+M[1]%12) + (M[7] == "p" ? 12 : 0), 0, 0, 0);
/* TODO: 1904 adjustment, keep in sync with base date */
if(!M[2]) return new Date(1899,11,30,(+M[1]%12) + (M[7] == "p" ? 12 : 0), 0, 0, 0);
if(M[3]) {
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);
else return new Date(1900,0,0,(M[7] == "p" ? 12 : 0), +M[1], +M[2], parseFloat(M[3])*1000);
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);
else return new Date(1899,11,30,(M[7] == "p" ? 12 : 0), +M[1], +M[2], parseFloat(M[3])*1000);
}
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);
else return new Date(1900,0,0,(+M[1]%12) + (M[7] == "p" ? 12 : 0), +M[2], 0, 0);
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);
else return new Date(1899,11,30,(+M[1]%12) + (M[7] == "p" ? 12 : 0), +M[2], 0, 0);
}
var lower_months = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'];
function fuzzydate(s/*:string*/)/*:Date*/ {
var lower = s.toLowerCase();
var lnos = lower.replace(/\s+/g, "");
var lnos = lower.replace(/\s+/g, " ").trim();
var M = lnos.match(FDRE1);
if(M) return fuzzytime1(M);

Expand Down
8 changes: 4 additions & 4 deletions bits/40_harb.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,12 +960,12 @@ var PRN = /*#__PURE__*/(function() {
else if(s == "TRUE") { cell.t = 'b'; cell.v = true; }
else if(s == "FALSE") { cell.t = 'b'; cell.v = false; }
else if(!isNaN(v = fuzzynum(s))) { cell.t = 'n'; if(o.cellText !== false) cell.w = s; cell.v = v; }
else if(!isNaN(fuzzydate(s).getDate()) || _re && s.match(_re)) {
else if(!isNaN((v = fuzzydate(s)).getDate()) || _re && s.match(_re)) {
cell.z = o.dateNF || table_fmt[14];
var k = 0;
if(_re && s.match(_re)){ s=dateNF_fix(s, o.dateNF, (s.match(_re)||[])); k=1; }
if(o.cellDates) { cell.t = 'd'; cell.v = parseDate(s, k); }
else { cell.t = 'n'; cell.v = datenum(parseDate(s, k)); }
if(_re && s.match(_re)){ s=dateNF_fix(s, o.dateNF, (s.match(_re)||[])); k=1; v = parseDate(s, k); }
if(o.cellDates) { cell.t = 'd'; cell.v = v; }
else { cell.t = 'n'; cell.v = datenum(v); }
if(o.cellText !== false) cell.w = SSF_format(cell.z, cell.v instanceof Date ? datenum(cell.v):cell.v);
if(!o.cellNF) delete cell.z;
} else {
Expand Down
8 changes: 3 additions & 5 deletions demos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ can be installed with Bash on Windows or with `cygwin`.
### Included Demos

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

Expand All @@ -43,8 +42,7 @@ can be installed with Bash on Windows or with `cygwin`.
**Platforms and Integrations**
- [`Command-Line Tools`](https://docs.sheetjs.com/docs/getting-started/demos/cli)
- [`NodeJS Server-Side Processing`](server/)
- [`Deno`](deno/)
- [`Electron`](electron/)
- [`Electron`](https://docs.sheetjs.com/docs/getting-started/demos/desktop#electron)
- [`NW.js`](https://docs.sheetjs.com/docs/getting-started/demos/desktop#nwjs)
- [`Chrome / Chromium Extension`](https://docs.sheetjs.com/docs/getting-started/demos/chromium)
- [`Google Sheets API`](https://docs.sheetjs.com/docs/getting-started/demos/gsheet)
Expand All @@ -68,7 +66,7 @@ can be installed with Bash on Windows or with `cygwin`.
- [`rollup`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#rollup)
- [`snowpack`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#snowpack)
- [`swc`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#swc)
- [`systemjs`](systemjs/)
- [`systemjs`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#systemjs)
- [`vite`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#vite)
- [`webpack 2.x`](webpack/)
- [`wmr`](https://docs.sheetjs.com/docs/getting-started/demos/bundler#wmr)
Expand Down
15 changes: 0 additions & 15 deletions demos/electron/Makefile

This file was deleted.

54 changes: 2 additions & 52 deletions demos/electron/README.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,6 @@
# Electron

This library is compatible with Electron and should just work out of the box.
The demonstration uses Electron 18.2.0. The library is added via `require` from
the renderer process.

The library can also be required from the main process, as shown in this demo
to render a version string in the About dialog on OSX.

The standard HTML5 `FileReader` techniques from the browser apply to Electron.
This demo includes a drag-and-drop box as well as a file input box, mirroring
the [SheetJS Data Preview Live Demo](http://oss.sheetjs.com/sheetjs/)

The core data in this demo is an editable HTML table. The readers build up the
table using `sheet_to_html` (with `editable:true` option) and the writers scrape
the table using `table_to_book`.

The demo project is structured for `electron-forge`:
- `npm start` will start the app.
- `npm run make` will build a standalone app.

The standalone app was tested on an Intel Mac (`darwin-x64`).

## Reading and Writing Files

Since electron provides an `fs` implementation, `readFile` and `writeFile` can
be used in conjunction with the standard dialog windows. For example:

```js
/* from app code, require('electron').remote calls back to main process */
var dialog = require('electron').remote.dialog;

/* show a file-open dialog and read the first selected file */
var o = dialog.showOpenDialog({ properties: ['openFile'] });
var workbook = XLSX.readFile(o[0]);

/* show a file-save dialog and write the workbook */
var o = dialog.showSaveDialog();
XLSX.writeFile(workbook, o);
```

## Breaking Changes in Electron

The first version of this demo used Electron 1.7.5.

Electron 9.0.0 and later require the preference `nodeIntegration: true` in order
to `require('XLSX')` in the renderer process.

Electron 12.0.0 and later also require `worldSafeExecuteJavascript: true` and
`contextIsolation: true`.

Electron 14+ must use `@electron/remote` instead of `remote`.


[The new demo](https://docs.sheetjs.com/docs/getting-started/demos/desktop#electron)
includes an improved example and detailed explanations.

[![Analytics](https://ga-beacon.appspot.com/UA-36810333-1/SheetJS/js-xlsx?pixel)](https://github.com/SheetJS/js-xlsx)
39 changes: 0 additions & 39 deletions demos/electron/index.html

This file was deleted.

79 changes: 0 additions & 79 deletions demos/electron/index.js

This file was deleted.

30 changes: 0 additions & 30 deletions demos/electron/main.js

This file was deleted.

51 changes: 0 additions & 51 deletions demos/electron/package.json

This file was deleted.

2 changes: 0 additions & 2 deletions demos/meteor/.gitignore

This file was deleted.

14 changes: 0 additions & 14 deletions demos/meteor/Makefile

This file was deleted.

Loading

0 comments on commit fdbbf2d

Please sign in to comment.