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 to capture MONTHDIG_YEAR, MM(fd)YYYY, '06/1992'
author
Ben Vogt <[email protected]>
date
2017-04-01 14:51:13
stats
2 file(s) changed, 49 insertions(+), 0 deletions(-)
files
src/RawFormulas/Date.ts
tests/DateFormulasTest.ts
 1diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
 2index 9cda747..9595694 100644
 3--- a/src/RawFormulas/Date.ts
 4+++ b/src/RawFormulas/Date.ts
 5@@ -63,7 +63,11 @@ const YEAR_MONTHDIG = DateRegExBuilder.DateRegExBuilder()
 6   .OPTIONAL_DAYNAME().OPTIONAL_COMMA().YYYY14().FLEX_DELIMITER().MM()
 7   .end()
 8   .build();
 9-// const MONTHDIG_YEAR;
10+const MONTHDIG_YEAR = DateRegExBuilder.DateRegExBuilder()
11+  .start()
12+  .OPTIONAL_DAYNAME().OPTIONAL_COMMA().MM().FLEX_DELIMITER().YYYY14()
13+  .end()
14+  .build();
15 // const YEAR_MONTHNAME;
16 // const MONTHNAME_YEAR;
17 
18@@ -128,6 +132,17 @@ var DATEVALUE = function (...values) : number {
19     }
20   }
21 
22+  // Check MONTHDIG_YEAR, MM(fd)YYYY, '06/1992'
23+  // NOTE: Must come before MONTHDIG_DAY_YEAR matching.
24+  if (m === undefined) {
25+    var matches = dateString.match(MONTHDIG_YEAR);
26+    if (matches && matches.length === 6) {
27+      var years = parseInt(matches[5]);
28+      var months = parseInt(matches[3]) - 1; // Months are zero indexed.
29+      m = createMoment(years, months, 0);
30+    }
31+  }
32+
33   // Check MONTHDIG_DAY_YEAR, MM(fd)DD(fd)YYYY, "06/24/1992"
34   if (m === undefined) {
35     var matches = dateString.match(MONTHDIG_DAY_YEAR);
36diff --git a/tests/DateFormulasTest.ts b/tests/DateFormulasTest.ts
37index d58ef13..baa9e8d 100644
38--- a/tests/DateFormulasTest.ts
39+++ b/tests/DateFormulasTest.ts
40@@ -243,7 +243,38 @@ assertEquals(DATEVALUE("2017/01"), 42736);
41 assertEquals(DATEVALUE("2017-01"), 42736);
42 assertEquals(DATEVALUE("2017.01"), 42736);
43 assertEquals(DATEVALUE("2017, 01"), 42736);
44-
45+// Comma delimiters should be followed by spaces.
46+catchAndAssertEquals(function() {
47+  DATEVALUE("2017,01");
48+}, ERRORS.VALUE_ERROR);
49+// MONTHDIG_YEAR, MM(fd)YYYY, '06/1992' ================================================================================
50+assertEquals(DATEVALUE("01/2017"), 42736);
51+assertEquals(DATEVALUE("02/2017"), 42767);
52+assertEquals(DATEVALUE("03/2017"), 42795);
53+assertEquals(DATEVALUE("04/2017"), 42826);
54+assertEquals(DATEVALUE("05/2017"), 42856);
55+assertEquals(DATEVALUE("06/2017"), 42887);
56+assertEquals(DATEVALUE("07/2017"), 42917);
57+assertEquals(DATEVALUE("08/2017"), 42948);
58+assertEquals(DATEVALUE("09/2017"), 42979);
59+assertEquals(DATEVALUE("10/2017"), 43009);
60+assertEquals(DATEVALUE("11/2017"), 43040);
61+assertEquals(DATEVALUE("12/2017"), 43070);
62+// delimiter tests
63+assertEquals(DATEVALUE("Thursday 01/2017"), 42736);
64+assertEquals(DATEVALUE("Thursday, 01/2017"), 42736);
65+assertEquals(DATEVALUE("1/2017"), 42736);
66+assertEquals(DATEVALUE("01-2017"), 42736);
67+assertEquals(DATEVALUE("01.2017"), 42736);
68+assertEquals(DATEVALUE("01, 2017"), 42736);
69+// Comma delimiters should be followed by spaces.
70+catchAndAssertEquals(function() {
71+  DATEVALUE("01,2017");
72+}, ERRORS.VALUE_ERROR);
73+// 0 is not a month
74+catchAndAssertEquals(function() {
75+  DATEVALUE("0/2017");
76+}, ERRORS.VALUE_ERROR);
77 
78 
79