spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[TypeConverter, DateRegExBuilder] parsing hour, minute, second 9-digits long
author
Ben Vogt <[email protected]>
date
2017-05-19 02:01:34
stats
4 file(s) changed, 22 insertions(+), 7 deletions(-)
files
README.md
package.json
src/Utilities/DateRegExBuilder.ts
tests/Utilities/TypeConverterTest.ts
 1diff --git a/README.md b/README.md
 2index f8f1080..87508ab 100644
 3--- a/README.md
 4+++ b/README.md
 5@@ -29,9 +29,6 @@ helpers to convert, display, and do normal operations with them.
 6 Contingent upon cells having formats or types for primitives.
 7 
 8 
 9-### Verify that all N-times ({2,9}) are correct, and we're not parsing numbers too big inside Date formulas.
10-
11-
12 ### Scrape jsdocs for functions, put in simple index.html, doc.md files to serve up simple documentation
13 
14 
15diff --git a/package.json b/package.json
16index fda98d1..7b931af 100644
17--- a/package.json
18+++ b/package.json
19@@ -1,7 +1,7 @@
20 {
21   "name": "spreadsheet",
22   "version": "1.0.0",
23-  "description": "TypeScript implementation of a spreadsheet.",
24+  "description": "TypeScript/javascript implementation of a spreadsheet.",
25   "scripts": {
26     "clean": "rm -rf output/* && rm -rf test_output/*",
27     "build": "tsc && cp lib/parser.js output/",
28diff --git a/src/Utilities/DateRegExBuilder.ts b/src/Utilities/DateRegExBuilder.ts
29index a25cb27..136971a 100644
30--- a/src/Utilities/DateRegExBuilder.ts
31+++ b/src/Utilities/DateRegExBuilder.ts
32@@ -169,8 +169,8 @@ class DateRegExBuilder {
33   }
34 
35   /**
36-   * Add a capture group for capturing timestamps including: "10am", "10:10", "10:10pm", "10:10:10", "10:10:10am", along
37-   * with zero or more spaces after semi colons, AM or PM, and unlimited number of digits per unit.
38+   * Add an optional capture group for capturing timestamps including: "10am", "10:10", "10:10pm", "10:10:10",
39+   * "10:10:10am", along with zero or more spaces after semi colons, AM or PM, and unlimited number of digits per unit.
40    * @returns {DateRegExBuilder} builder
41    * @constructor
42    */
43@@ -179,8 +179,17 @@ class DateRegExBuilder {
44     return this;
45   }
46 
47+
48+  /**
49+   * Add a capture group for capturing timestamps including: "10am", "10:10", "10:10pm", "10:10:10",
50+   * "10:10:10am", along with zero or more spaces after semi colons, AM or PM, and unlimited number of digits per unit.
51+   * See https://regex101.com/r/0bmj5n/1/ for more information of 9-digit maximum. One series, "12:00001989198298am",
52+   * has a maximum of 10 digits: "0*(?:[1-9]{1}[0-9]{0,9})?"
53+   * @returns {DateRegExBuilder} builder
54+   * @constructor
55+   */
56   TIMESTAMP_UNITS_CAPTURE_GROUP() : DateRegExBuilder {
57-    this.regexString += "(\\s*([0-9]+)()()\\s*(am|pm)\\s*$)|(\\s*([0-9]+):\\s*([0-9]+)()()\\s*$)|(\\s*(([0-9]+):\\s*([0-9]+)()\\s*(am|pm))\\s*$)|(\\s*(([0-9]+):\\s*([0-9]+):\\s*([0-9]+)())\\s*$)|(\\s*(([0-9]+):\\s*([0-9]+):\\s*([0-9]+)\\s*(am|pm))\\s*$)";
58+    this.regexString += "(\\s*(0*(?:[1-9]{1}[0-9]{0,8})?)()()\\s*(am|pm)\\s*$)|(\\s*(0*(?:[1-9]{1}[0-9]{0,8})?):\\s*(0*(?:[1-9]{1}[0-9]{0,8})?)()()\\s*$)|(\\s*((0*(?:[1-9]{1}[0-9]{0,8})?):\\s*(0*(?:[1-9]{1}[0-9]{0,9})?)()\\s*(am|pm))\\s*$)|(\\s*((0*(?:[1-9]{1}[0-9]{0,8})?):\\s*(0*(?:[1-9]{1}[0-9]{0,8})?):\\s*(0*(?:[1-9]{1}[0-9]{0,8})?)())\\s*$)|(\\s*((0*(?:[1-9]{1}[0-9]{0,8})?):\\s*(0*(?:[1-9]{1}[0-9]{0,8})?):\\s*(0*(?:[1-9]{1}[0-9]{0,8})?)\\s*(am|pm))\\s*$)";
59     return this;
60   }
61 
62diff --git a/tests/Utilities/TypeConverterTest.ts b/tests/Utilities/TypeConverterTest.ts
63index 130595e..c133ce4 100644
64--- a/tests/Utilities/TypeConverterTest.ts
65+++ b/tests/Utilities/TypeConverterTest.ts
66@@ -879,6 +879,15 @@ test("TypeConverter.stringToDateNumber", function () {
67   assertEquals(TypeConverter.stringToDateNumber("January-2017 10: 10 pm"), 42736);
68   assertEquals(TypeConverter.stringToDateNumber("January-2017 10: 10: 10"), 42736);
69   assertEquals(TypeConverter.stringToDateNumber("January-2017  10: 10: 10    am  "), 42736);
70+  assertEquals(TypeConverter.stringToDateNumber("January-2000 100000000:100000000:100000000"), 4273794);
71+  assertEquals(TypeConverter.stringToDateNumber("1999/1/01 00200000000:00000999999999:00000923231312"), 9074624);
72+  assertEquals(TypeConverter.stringToDateNumber("1992/1/13 12:00001989198298am"), 1415003);
73+  catchAndAssertEquals(function() {
74+    TypeConverter.stringToDateNumber("1992/1/13 12:000019891982980am");
75+  }, VALUE_ERROR);
76+  catchAndAssertEquals(function() {
77+    TypeConverter.stringToDateNumber("January-2000 100000000:100000000:1001000000");
78+  }, VALUE_ERROR);
79 });
80 
81