spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Adding some notes and reconsidering how I'm approaching regular expressions for dates
author
Ben Vogt <[email protected]>
date
2017-03-26 22:40:35
stats
3 file(s) changed, 145 insertions(+), 8 deletions(-)
files
README.md
src/RawFormulas/Date.ts
tests/DateFormulasTest.ts
  1diff --git a/README.md b/README.md
  2index 3189b28..137bebe 100644
  3--- a/README.md
  4+++ b/README.md
  5@@ -48,26 +48,62 @@ Although dollar functions look like they just format `number`s, it seems like th
  6 This means that we should do dollar->number casting in all casting functions. For now, just using number primitive.
  7 See `DOLLAR` function for more info.
  8 
  9-### Date TODOS
 10-#### Dates have special types
 11+
 12+
 13+# The Great Date Refactoring (TM)
 14+### Different Date Formats
 15+```
 16+YYYY/MM/DD       YEAR_MONTHDIG_DAY_SLASH_DELIMIT
 17+YYYY-MM-DD       YEAR_MONTHDIG_DAY_HYPHEN_DELIMIT
 18+YYYY.MM.DD       YEAR_MONTHDIG_DAY_DOT_DELIMIT
 19+YYYY MM DD       YEAR_MONTHDIG_DAY_SPACE_DELIMIT
 20+YYYY, MM, DD     YEAR_MONTHDIG_DAY_COMMA_DELIMIT
 21+Month DD YYYY    MONTHNAME_DAY_YEAR_COMMON_DELIMITERS
 22+DD Month YYYY    DAY_MONTHNAME_YEAR_COMMON_DELIMITERS
 23+Month DD         MONTHNAME_DAY_COMMON_DELIMITERS
 24+DD Month         DAY_MONTHNAME_COMMON_DELIMITERS
 25+Month YYYY       MONTHNAME_YEAR_COMMON_DELIMITERS
 26+YYYY Month       YEAR_MONTHNAME_COMMON_DELIMITERS
 27+MM/DD            MONTHDIG_DAY_SLASH_DELIMIT
 28+MM-DD            MONTHDIG_DAY_HYPHEN_DELIMIT
 29+MM DD            MONTHDIG_DAY_SPACE_DELIMIT
 30+MM.DD            MONTHDIG_DAY_DOT_DELIMIT
 31+MM, DD           MONTHDIG_DAY_COMMA_DELIMIT
 32+MM/YYYY          MONTHDIG_YEAR_SLASH_DELIMIT
 33+MM-YYYY          MONTHDIG_YEAR_HYPHEN_DELIMIT
 34+MM YYYY          MONTHDIG_YEAR_SPACE_DELIMIT
 35+MM.YYYY          MONTHDIG_YEAR_DOT_DELIMIT
 36+MM, YYYY         MONTHDIG_YEAR_COMMA_DELIMIT
 37+```
 38+
 39+### Different Time Formats
 40+HHam             HOUR_MERIDIEM
 41+HH:MM            HOURS_MINUTES_OVERFLOW
 42+HH:MMam          HOURS_MINUTES_OVERFLOW_MERIDIEM
 43+HH:MM:SS         HOURS_MINUTES_SECONDS_OVERFLOW
 44+HH:MM:SSam       HOURS_MINUTES_SECONDS_OVERFLOW_MERIDIEM
 45+
 46+
 47+* Dates have special types
 48 Like dollars, dates are special types, but can be compared as if they're primatives. For example, this statement is
 49 valid inside a cell: `=DATE(1992, 6, 6) > =DATE(1992, 6, 10)`. We should check types and and have Date-to-number
 50 conversion inside parser.js.
 51 
 52-#### Organize tests in a way that makes sense.
 53+* Organize tests in a way that makes sense.
 54 Annotate them, and standardize the error checking for errors like REF, NA, NUM, VALUE, etc.
 55 
 56-#### Test all ExcelDate functions
 57+* Test all ExcelDate functions
 58 Right now we're just using the number of days since 1900, but we should check the other functions.
 59 
 60-#### YYYY/MM/DD HH:mm needs more thurough testing
 61+* YYYY/MM/DD HH:mm needs more thurough testing
 62 
 63-#### Verify that all white-space wild cards are implemented properly
 64+* Verify that all white-space wild cards are implemented properly
 65 
 66-#### Verify that all N-times ({2,9}) are correct, and we're not parsing numbers too big.
 67+* Verify that all N-times ({2,9}) are correct, and we're not parsing numbers too big.
 68 
 69-#### Many times I use `\s*` when I actaully mean `\s+`
 70+* Many times I use `\s*` when I actaully mean `\s+`
 71 Or the are times when I mean "Feb 20 2019" or "Feb 20,2019", and either is correct.
 72 
 73-#### Use `startOf('year')` to zero out all dates before building them up.
 74+* Use `startOf('year')` to zero out all dates before building them up.
 75 No current tests should change because of this but it should eliminate some edge cases.
 76+
 77diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
 78index d1dc4dc..834e583 100644
 79--- a/src/RawFormulas/Date.ts
 80+++ b/src/RawFormulas/Date.ts
 81@@ -47,21 +47,84 @@ var DATE = function (...values) {
 82  * @param values[0] date_string - The string representing the date. Understood formats include any date format which is
 83  * normally auto-converted when entered, without quotation marks, directly into a cell. Understood formats may depend on
 84  * region and language settings. Examples include:
 85- * "1999/1/13"              DONE
 86- * "1/13/1999"              DONE
 87- * "1999/1/13 10am"         DONE
 88- * "1999/1/13 10:22"        DONE
 89- * "1999/1/13 10:10am"      DONE
 90- * "1999/1/13 10:10:10"     DONE
 91- * "1999/1/13 10:10:10pm"   DONE
 92- * "Sun Feb 09 2017"        DONE
 93- * "Sun 09 Feb 2017"        DONE
 94- * "Feb-2017"               DONE
 95- * "Feb 22"                 DONE
 96- * "22-Feb"
 97+ * "1999/1/13"                    DONE
 98+ * "1999-1-13"
 99+ * "1999 1 13"
100+ * "1999.1.13"
101+ * "1999, 1, 13"
102+ * "1/13/1999"                    DONE
103+ * "1-13-1999"
104+ * "1 13 1999"
105+ * "1.13.1999"
106+ * "1, 13, 1999"
107+ * "1999/1/13 10am"               DONE
108+ * "1999-1-13 10am"
109+ * "1999 1 13 10am"
110+ * "1999.1.13 10am"
111+ * "1999/1/13 10:22"              DONE
112+ * "1999-1-13 10:22"
113+ * "1999 1 13 10:22"
114+ * "1999.1.13 10:22"
115+ * "1999/1/13 10:10am"            DONE
116+ * "1999-1-13 10:10am"
117+ * "1999 1 13 10:10am"
118+ * "1999.1.13 10:10am"
119+ * "1999/1/13 10:10:10"           DONE
120+ * "1999-1-13 10:10:10"
121+ * "1999 1 13 10:10:10"
122+ * "1999.1.13 10:10:10"
123+ * "1999/1/13 10:10:10pm"         DONE
124+ * "1999-1-13 10:10:10pm"
125+ * "1999 1 13 10:10:10pm"
126+ * "1999.1.13 10:10:10pm"
127+ * "Sun Feb 09 2017"              DONE
128+ * "Sun Feb 09 2017 10am"
129+ * "Sun Feb 09 2017 10:10"
130+ * "Sun Feb 09 2017 10:10am"
131+ * "Sun Feb 09 2017 10:10:10"
132+ * "Sun Feb 09 2017 10:10:10pm"
133+ * "Sun 09 Feb 2017"              DONE
134+ * "Sun 09 Feb 2017 10am"
135+ * "Sun 09 Feb 2017 10:10"
136+ * "Sun 09 Feb 2017 10:10am"
137+ * "Sun 09 Feb 2017 10:10:10"
138+ * "Sun 09 Feb 2017 10:10:10pm"
139+ * "Feb-2017"                     DONE
140+ * "Feb-2017 10am"
141+ * "Feb-2017 10:10"
142+ * "Feb-2017 10:10am"
143+ * "Feb-2017 10:10:10"
144+ * "Feb-2017 10:10:10pm"
145+ * "Feb 22"                       DONE
146+ * "Feb 22 10am"
147+ * "Feb 22 10:10"
148+ * "Feb 22 10:10am"
149+ * "Feb 22 10:10:10"
150+ * "Feb 22 10:10:10pm"
151+ * "22-Feb"                       DONE
152+ * "22-Feb 10am"
153+ * "22-Feb 10:10"
154+ * "22-Feb 10:10am"
155+ * "22-Feb 10:10:10"
156+ * "22-Feb 10:10:10pm"
157+ * "22-Feb-2017"
158+ * "22-Feb-2017 10am"
159+ * "22-Feb-2017 10:10"
160+ * "22-Feb-2017 10:10am"
161+ * "22-Feb-2017 10:10:10"
162+ * "22-Feb-2017 10:10:10pm"
163  * "10-22"
164+ * "10-22 10am"
165+ * "10-22 10:10"
166+ * "10-22 10:10am"
167+ * "10-22 10:10:10"
168+ * "10-22 10:10:10pm"
169  * "10/2022"
170- * "Sun Mar 05 2017 10:40:26"
171+ * "10-2022 10am"
172+ * "10-2022 10:10"
173+ * "10-2022 10:10am"
174+ * "10-2022 10:10:10"
175+ * "10-2022 10:10:10pm"
176  * @returns {number} of days since 1900/1/1, inclusively.
177  * @constructor
178  */
179@@ -355,6 +418,28 @@ var DATEVALUE = function (...values) : number {
180     }
181   }
182 
183+  // Check Month DD
184+  if (m === undefined) {
185+    // For reference: https://regex101.com/r/hujaIk/7
186+    // Code here.
187+  }
188+
189+  // Check Month DD Year
190+  if (m === undefined) {
191+    // Code here.
192+  }
193+
194+  // Check MM-DD
195+  if (m === undefined) {
196+    // Code here.
197+  }
198+
199+  // Check MM-YYYY
200+  if (m === undefined) {
201+    // Code here.
202+  }
203+
204+
205   // If we've not been able to parse the date by now, then we cannot parse it at all.
206   if (m === undefined || !m.isValid()) {
207     throw new CellError(VALUE_ERROR, "DATEVALUE parameter '" + dateString + "' cannot be parsed to date/time.");
208diff --git a/tests/DateFormulasTest.ts b/tests/DateFormulasTest.ts
209index d1d9c1c..a2d0104 100644
210--- a/tests/DateFormulasTest.ts
211+++ b/tests/DateFormulasTest.ts
212@@ -429,4 +429,4 @@ catchAndAssertEquals(function() {
213 }, ERRORS.VALUE_ERROR);
214 catchAndAssertEquals(function() {
215   DATEVALUE("20.Dec");// need space if using period
216-}, ERRORS.VALUE_ERROR);
217\ No newline at end of file
218+}, ERRORS.VALUE_ERROR);