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 MONTHNAME_YEAR, Month(fd)YYYY, 'Aug 1992'
author
Ben Vogt <[email protected]>
date
2017-04-01 15:04:51
stats
2 file(s) changed, 42 insertions(+), 1 deletions(-)
files
src/RawFormulas/Date.ts
tests/DateFormulasTest.ts
 1diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
 2index 148ed36..0c263fc 100644
 3--- a/src/RawFormulas/Date.ts
 4+++ b/src/RawFormulas/Date.ts
 5@@ -73,7 +73,11 @@ const YEAR_MONTHNAME = DateRegExBuilder.DateRegExBuilder()
 6   .OPTIONAL_DAYNAME().OPTIONAL_COMMA().YYYY14().FLEX_DELIMITER().MONTHNAME()
 7   .end()
 8   .build();
 9-// const MONTHNAME_YEAR;
10+const MONTHNAME_YEAR = DateRegExBuilder.DateRegExBuilder()
11+  .start()
12+  .OPTIONAL_DAYNAME().OPTIONAL_COMMA().MONTHNAME().FLEX_DELIMITER().YYYY14()
13+  .end()
14+  .build();
15 
16 /**
17  * Converts a provided date string in a known format to a date value.
18@@ -162,6 +166,17 @@ var DATEVALUE = function (...values) : number {
19     }
20   }
21 
22+  // Check MONTHNAME_YEAR, Month(fd)YYYY, 'Aug 1992'
23+  // NOTE: Needs to come before DAY_MONTHNAME_YEAR matching.
24+  if (m === undefined) {
25+    var matches = dateString.match(MONTHNAME_YEAR);
26+    if (matches && matches.length === 6) {
27+      var years = parseInt(matches[5]);
28+      var monthName = matches[3];
29+      m = createMoment(years, monthName, 0);
30+    }
31+  }
32+
33   // Check DAY_MONTHNAME_YEAR, DD(fd)Month(fd)YYYY, '24/July/1992'
34   if (m === undefined) {
35     var matches = dateString.match(DAY_MONTHNAME_YEAR);
36diff --git a/tests/DateFormulasTest.ts b/tests/DateFormulasTest.ts
37index 122a537..6e7e326 100644
38--- a/tests/DateFormulasTest.ts
39+++ b/tests/DateFormulasTest.ts
40@@ -299,6 +299,32 @@ assertEquals(DATEVALUE("2017, January"), 42736);
41 catchAndAssertEquals(function() {
42   DATEVALUE("2017,January");
43 }, ERRORS.VALUE_ERROR);
44+// MONTHNAME_YEAR, Month(fd)YYYY, 'Aug 1992' ===========================================================================
45+assertEquals(DATEVALUE("January 2017"), 42736);
46+assertEquals(DATEVALUE("February 2017"), 42767);
47+assertEquals(DATEVALUE("March 2017"), 42795);
48+assertEquals(DATEVALUE("April 2017"), 42826);
49+assertEquals(DATEVALUE("May 2017"), 42856);
50+assertEquals(DATEVALUE("June 2017"), 42887);
51+assertEquals(DATEVALUE("July 2017"), 42917);
52+assertEquals(DATEVALUE("August 2017"), 42948);
53+assertEquals(DATEVALUE("September 2017"), 42979);
54+assertEquals(DATEVALUE("October 2017"), 43009);
55+assertEquals(DATEVALUE("November 2017"), 43040);
56+assertEquals(DATEVALUE("December 2017"), 43070);
57+// delimiter tests
58+assertEquals(DATEVALUE("Thursday January 2017"), 42736);
59+assertEquals(DATEVALUE("Thursday, January 2017"), 42736);
60+assertEquals(DATEVALUE("January/2017"), 42736);
61+assertEquals(DATEVALUE("January-2017"), 42736);
62+assertEquals(DATEVALUE("January.2017"), 42736);
63+assertEquals(DATEVALUE("January, 2017"), 42736);
64+// Comma delimiters should be followed by spaces.
65+catchAndAssertEquals(function() {
66+  DATEVALUE("January,2017");
67+}, ERRORS.VALUE_ERROR);
68+
69+
70 
71 
72