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