spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Using DateRegExBuilder for 'DAY_MONTHNAME_YEAR_COMMON_DELIMITERS, DD Month YYYY, 20 September 1992'
author
Ben Vogt <[email protected]>
date
2017-03-27 00:12:09
stats
3 file(s) changed, 15 insertions(+), 2 deletions(-)
files
README.md
src/RawFormulas/Date.ts
src/RawFormulas/Utils.ts
 1diff --git a/README.md b/README.md
 2index c12f1b0..891aa01 100644
 3--- a/README.md
 4+++ b/README.md
 5@@ -65,7 +65,7 @@ MM.DD.YYYY       MONTHDIG_DAY_YEAR_DOT_DELIMIT           months, days, years
 6 MM DD YYYY       MONTHDIG_DAY_YEAR_SPACE_DELIMIT         months, days, years
 7 MM, DD, YYYY     MONTHDIG_DAY_YEAR_COMMA_DELIMIT         months, days, years
 8 Month DD YYYY    MONTHNAME_DAY_YEAR_COMMON_DELIMITERS    monthName, days, years        // TODO: right now only comma...
 9-DD Month YYYY    DAY_MONTHNAME_YEAR_COMMON_DELIMITERS    days, monthName, years
10+DD Month YYYY    DAY_MONTHNAME_YEAR_COMMON_DELIMITERS    days, monthName, years        // TODO: right now only comma...
11 Month DD         MONTHNAME_DAY_COMMON_DELIMITERS         monthName, days
12 DD Month         DAY_MONTHNAME_COMMON_DELIMITERS         days, monthName
13 Month YYYY       MONTHNAME_YEAR_COMMON_DELIMITERS        monthName, years
14diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
15index bfbd3cb..4aaeb3f 100644
16--- a/src/RawFormulas/Date.ts
17+++ b/src/RawFormulas/Date.ts
18@@ -388,10 +388,16 @@ var DATEVALUE = function (...values) : number {
19     }
20   }
21 
22-  // Check (Dayname) DD Month YYYY
23+  // Check DAY_MONTHNAME_YEAR_COMMON_DELIMITERS, DD Month YYYY, 20 September 1992
24   if (m === undefined) {
25     // For reference: https://regex101.com/r/22TD0r/3
26-    var matches = dateString.match(/^\s*(sunday|monday|tuesday|wednesday|thursday|friday|saturday|sun|mon|tues|wed|thur|fri|sat)?,?\s*(0?[0-9]|1[0-9]|2[0-9]|3[0-1]),?\s*(january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|jun|jul|aug|sep|oct|nov|dec),?\s*([0-9]{4}|[1-9][0-9]{2}|[0-9]{2})\s*$/i);
27+    const REG = DateRegExBuilder.DateRegExBuilder()
28+      .start()
29+      .OPTIONAL_DAYNAME().OPTIONAL_COMMA().N_SPACES().DD().OPTIONAL_COMMA().N_SPACES().MONTHNAME().OPTIONAL_COMMA()
30+      .N_SPACES().YYY_OR_YYYY() // TODO: YYY_OR_YYYY possibly unnecessary. Rolling past to get these converted.
31+      .end()
32+      .build();
33+    var matches = dateString.match(REG);
34     if (matches && matches.length === 5) {
35       var years = parseInt(matches[4]);
36       var monthName = matches[3];
37diff --git a/src/RawFormulas/Utils.ts b/src/RawFormulas/Utils.ts
38index aa2e328..a3fac88 100644
39--- a/src/RawFormulas/Utils.ts
40+++ b/src/RawFormulas/Utils.ts
41@@ -471,6 +471,11 @@ class DateRegExBuilder {
42     return this;
43   }
44 
45+  YYY_OR_YYYY() : DateRegExBuilder {
46+    this.regexString += "([0-9]{4}|[1-9][0-9]{2}|[0-9]{2})";
47+    return this;
48+  }
49+
50   /**
51    *
52    * @returns {DateRegExBuilder}