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 'YYYY/MM/DD HH:mm'
author
Ben Vogt <[email protected]>
date
2017-03-26 23:14:05
stats
3 file(s) changed, 75 insertions(+), 30 deletions(-)
files
README.md
src/RawFormulas/Date.ts
src/RawFormulas/Utils.ts
  1diff --git a/README.md b/README.md
  2index 27aaf10..0577656 100644
  3--- a/README.md
  4+++ b/README.md
  5@@ -53,36 +53,39 @@ See `DOLLAR` function for more info.
  6 # The Great Date Refactoring (TM)
  7 ### Different Date Formats
  8 ```
  9-YYYY/MM/DD       YEAR_MONTHDIG_DAY_SLASH_DELIMIT
 10-YYYY-MM-DD       YEAR_MONTHDIG_DAY_HYPHEN_DELIMIT
 11-YYYY.MM.DD       YEAR_MONTHDIG_DAY_DOT_DELIMIT
 12-YYYY MM DD       YEAR_MONTHDIG_DAY_SPACE_DELIMIT
 13-MM/DD/YYYY       MONTHDIG_DAY_YEAR_SLASH_DELIMIT
 14-MM-DD-YYYY       MONTHDIG_DAY_YEAR_HYPHEN_DELIMIT
 15-MM.DD.YYYY       MONTHDIG_DAY_YEAR_DOT_DELIMIT
 16-MM DD YYYY       MONTHDIG_DAY_YEAR_SPACE_DELIMIT
 17-YYYY, MM, DD     YEAR_MONTHDIG_DAY_COMMA_DELIMIT
 18-Month DD YYYY    MONTHNAME_DAY_YEAR_COMMON_DELIMITERS
 19-DD Month YYYY    DAY_MONTHNAME_YEAR_COMMON_DELIMITERS
 20-Month DD         MONTHNAME_DAY_COMMON_DELIMITERS
 21-DD Month         DAY_MONTHNAME_COMMON_DELIMITERS
 22-Month YYYY       MONTHNAME_YEAR_COMMON_DELIMITERS
 23-YYYY Month       YEAR_MONTHNAME_COMMON_DELIMITERS
 24-MM/DD            MONTHDIG_DAY_SLASH_DELIMIT
 25-MM-DD            MONTHDIG_DAY_HYPHEN_DELIMIT
 26-MM DD            MONTHDIG_DAY_SPACE_DELIMIT
 27-MM.DD            MONTHDIG_DAY_DOT_DELIMIT
 28-MM, DD           MONTHDIG_DAY_COMMA_DELIMIT
 29-MM/YYYY          MONTHDIG_YEAR_SLASH_DELIMIT
 30-MM-YYYY          MONTHDIG_YEAR_HYPHEN_DELIMIT
 31-MM YYYY          MONTHDIG_YEAR_SPACE_DELIMIT
 32-MM.YYYY          MONTHDIG_YEAR_DOT_DELIMIT
 33-MM, YYYY         MONTHDIG_YEAR_COMMA_DELIMIT
 34+FORMAT           CONST NAME                              ACCESS ORDER
 35+YYYY/MM/DD       YEAR_MONTHDIG_DAY_SLASH_DELIMIT         years, months, days
 36+YYYY-MM-DD       YEAR_MONTHDIG_DAY_HYPHEN_DELIMIT        years, months, days
 37+YYYY.MM.DD       YEAR_MONTHDIG_DAY_DOT_DELIMIT           years, months, days
 38+YYYY MM DD       YEAR_MONTHDIG_DAY_SPACE_DELIMIT         years, months, days
 39+YYYY, MM, DD     YEAR_MONTHDIG_DAY_COMMA_DELIMIT         years, months, days
 40+MM/DD/YYYY       MONTHDIG_DAY_YEAR_SLASH_DELIMIT         months, days, years
 41+MM-DD-YYYY       MONTHDIG_DAY_YEAR_HYPHEN_DELIMIT        months, days, years
 42+MM.DD.YYYY       MONTHDIG_DAY_YEAR_DOT_DELIMIT           months, days, years
 43+MM DD YYYY       MONTHDIG_DAY_YEAR_SPACE_DELIMIT         months, days, years
 44+MM, DD, YYYY     MONTHDIG_DAY_YEAR_COMMA_DELIMIT         months, days, years
 45+Month DD YYYY    MONTHNAME_DAY_YEAR_COMMON_DELIMITERS    monthName, days, years
 46+DD Month YYYY    DAY_MONTHNAME_YEAR_COMMON_DELIMITERS    days, monthName, years
 47+Month DD         MONTHNAME_DAY_COMMON_DELIMITERS         monthName, days
 48+DD Month         DAY_MONTHNAME_COMMON_DELIMITERS         days, monthName
 49+Month YYYY       MONTHNAME_YEAR_COMMON_DELIMITERS        monthName, years
 50+YYYY Month       YEAR_MONTHNAME_COMMON_DELIMITERS        years, monthName
 51+MM/DD            MONTHDIG_DAY_SLASH_DELIMIT              months, days
 52+MM-DD            MONTHDIG_DAY_HYPHEN_DELIMIT             months, days
 53+MM DD            MONTHDIG_DAY_SPACE_DELIMIT              months, days
 54+MM.DD            MONTHDIG_DAY_DOT_DELIMIT                months, days
 55+MM, DD           MONTHDIG_DAY_COMMA_DELIMIT              months, days
 56+MM/YYYY          MONTHDIG_YEAR_SLASH_DELIMIT             months, years
 57+MM-YYYY          MONTHDIG_YEAR_HYPHEN_DELIMIT            months, years
 58+MM YYYY          MONTHDIG_YEAR_SPACE_DELIMIT             months, years
 59+MM.YYYY          MONTHDIG_YEAR_DOT_DELIMIT               months, years
 60+MM, YYYY         MONTHDIG_YEAR_COMMA_DELIMIT             months, years
 61 ```
 62 
 63 ### Different Time Formats
 64+FORMAT           CONST NAME
 65 HHam             HOUR_MERIDIEM
 66-HH:MM            HOURS_MINUTES_OVERFLOW
 67+HH:MM            HOURS_OVERFLOW_MINUTES_OVERFLOW
 68 HH:MMam          HOURS_MINUTES_OVERFLOW_MERIDIEM
 69 HH:MM:SS         HOURS_MINUTES_SECONDS_OVERFLOW
 70 HH:MM:SSam       HOURS_MINUTES_SECONDS_OVERFLOW_MERIDIEM
 71diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
 72index f64f2e8..ca8ddb5 100644
 73--- a/src/RawFormulas/Date.ts
 74+++ b/src/RawFormulas/Date.ts
 75@@ -199,7 +199,7 @@ var DATEVALUE = function (...values) : number {
 76     // For reference: https://regex101.com/r/m8FSCr/6
 77     const REG = DateRegExBuilder.DateRegExBuilder()
 78       .start()
 79-      .YYYY().SLASH_DELIMITOR().MM().SLASH_DELIMITOR().DD().zeroOrMoreSpaces().HH().MERIDIEM()
 80+      .YYYY().SLASH_DELIMITOR().MM().SLASH_DELIMITOR().DD().N_SPACES().HH().MERIDIEM()
 81       .end()
 82       .build();
 83     var matches = dateString.match(REG);
 84@@ -223,10 +223,15 @@ var DATEVALUE = function (...values) : number {
 85     }
 86   }
 87 
 88-  // Check YYYY/MM/DD HH:mm
 89+  // Check YEAR_MONTHDIG_DAY_SLASH_DELIMIT_WITH_HOURS_OVERFLOW_MINUTES_OVERFLOW, YYYY/MM/DD HH:mm, "1992/06/24 29:2922"
 90   if (m === undefined) {
 91     // For reference: https://regex101.com/r/xsqttP/4
 92-    var matches = dateString.match(/^\s*(([0-9][0-9][0-9][0-9])|([1-9][0-9][0-9]))\/([1-9]|0[1-9]|1[0-2])\/([1-9]|[0-2][0-9]|3[0-1])\s*([0-9]{1,}):\s*([0-9]{2,})\s*$/);
 93+    const REG = DateRegExBuilder.DateRegExBuilder()
 94+      .start()
 95+      .YYYY().SLASH_DELIMITOR().MM().SLASH_DELIMITOR().DD().N_SPACES().OVERLOAD_HH().SEMICOLON().OVERLOAD_MINITES()
 96+      .end()
 97+      .build();
 98+    var matches = dateString.match(REG);
 99     if (matches && matches.length === 8) {
100       var years = parseInt(matches[1]);
101       var months = parseInt(matches[4]) - 1; // Months are zero indexed.
102diff --git a/src/RawFormulas/Utils.ts b/src/RawFormulas/Utils.ts
103index 187537d..40a1005 100644
104--- a/src/RawFormulas/Utils.ts
105+++ b/src/RawFormulas/Utils.ts
106@@ -390,7 +390,7 @@ class DateRegExBuilder {
107    * Adds a match group for zero or more whitespace tokens.
108    * @returns {DateRegExBuilder}
109    */
110-  zeroOrMoreSpaces() : DateRegExBuilder {
111+  N_SPACES() : DateRegExBuilder {
112     this.regexString += DateRegExBuilder.ZERO_OR_MORE_SPACES;
113     return this;
114   }
115@@ -461,12 +461,45 @@ class DateRegExBuilder {
116     return this;
117   }
118 
119+  /**
120+   *
121+   * @returns {DateRegExBuilder}
122+   * @constructor
123+   */
124   MERIDIEM(): DateRegExBuilder {
125     this.regexString += "(am|pm)";
126     return this;
127   }
128 
129+  /**
130+   *
131+   * @returns {DateRegExBuilder}
132+   * @constructor
133+   */
134+  OVERLOAD_MINITES() : DateRegExBuilder {
135+    this.regexString += "([0-9]{2,})";
136+    return this;
137+  }
138 
139+  /**
140+   *
141+   * @returns {DateRegExBuilder}
142+   * @constructor
143+   */
144+  OVERLOAD_HH() : DateRegExBuilder {
145+    this.regexString += "([0-9]{1,})";
146+    return this;
147+  }
148+
149+  /**
150+   *
151+   * @returns {DateRegExBuilder}
152+   * @constructor
153+   */
154+  SEMICOLON(): DateRegExBuilder {
155+    this.regexString += ":" + DateRegExBuilder.ZERO_OR_MORE_SPACES;
156+    return this;
157+  }
158 
159   /**
160    * Builds the regular expression.