commit
message
Using DateRegExBuilder to capture YEAR_MONTHNAME, YYYY(fd)Month, '1992/Aug'
author
Ben Vogt <[email protected]>
date
2017-04-01 14:59:49
stats
2 file(s) changed,
40 insertions(+),
0 deletions(-)
files
src/RawFormulas/Date.ts
tests/DateFormulasTest.ts
1diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
2index 9595694..148ed36 100644
3--- a/src/RawFormulas/Date.ts
4+++ b/src/RawFormulas/Date.ts
5@@ -68,7 +68,11 @@ const MONTHDIG_YEAR = DateRegExBuilder.DateRegExBuilder()
6 .OPTIONAL_DAYNAME().OPTIONAL_COMMA().MM().FLEX_DELIMITER().YYYY14()
7 .end()
8 .build();
9-// const YEAR_MONTHNAME;
10+const YEAR_MONTHNAME = DateRegExBuilder.DateRegExBuilder()
11+ .start()
12+ .OPTIONAL_DAYNAME().OPTIONAL_COMMA().YYYY14().FLEX_DELIMITER().MONTHNAME()
13+ .end()
14+ .build();
15 // const MONTHNAME_YEAR;
16
17 /**
18@@ -175,6 +179,16 @@ var DATEVALUE = function (...values) : number {
19 }
20 }
21
22+ // Check YEAR_MONTHNAME, YYYY(fd)Month, '1992/Aug'
23+ if (m === undefined) {
24+ var matches = dateString.match(YEAR_MONTHNAME);
25+ if (matches && matches.length === 6) {
26+ var years = parseInt(matches[3]);
27+ var monthName = matches[5];
28+ m = createMoment(years, monthName, 0);
29+ }
30+ }
31+
32 // If we've not been able to parse the date by now, then we cannot parse it at all.
33 if (m === undefined || !m.isValid()) {
34 throw new CellError(VALUE_ERROR, "DATEVALUE parameter '" + dateString + "' cannot be parsed to date/time.");
35diff --git a/tests/DateFormulasTest.ts b/tests/DateFormulasTest.ts
36index baa9e8d..122a537 100644
37--- a/tests/DateFormulasTest.ts
38+++ b/tests/DateFormulasTest.ts
39@@ -275,8 +275,30 @@ catchAndAssertEquals(function() {
40 catchAndAssertEquals(function() {
41 DATEVALUE("0/2017");
42 }, ERRORS.VALUE_ERROR);
43-
44-
45+// YEAR_MONTHNAME, YYYY(fd)Month, '1992/Aug' ===========================================================================
46+assertEquals(DATEVALUE("2017 January"), 42736);
47+assertEquals(DATEVALUE("2017 February"), 42767);
48+assertEquals(DATEVALUE("2017 March"), 42795);
49+assertEquals(DATEVALUE("2017 April"), 42826);
50+assertEquals(DATEVALUE("2017 May"), 42856);
51+assertEquals(DATEVALUE("2017 June"), 42887);
52+assertEquals(DATEVALUE("2017 July"), 42917);
53+assertEquals(DATEVALUE("2017 August"), 42948);
54+assertEquals(DATEVALUE("2017 September"), 42979);
55+assertEquals(DATEVALUE("2017 October"), 43009);
56+assertEquals(DATEVALUE("2017 November"), 43040);
57+assertEquals(DATEVALUE("2017 December"), 43070);
58+// delimiter tests
59+assertEquals(DATEVALUE("Thursday 2017 January"), 42736);
60+assertEquals(DATEVALUE("Thursday, 2017 January"), 42736);
61+assertEquals(DATEVALUE("2017/January"), 42736);
62+assertEquals(DATEVALUE("2017-January"), 42736);
63+assertEquals(DATEVALUE("2017.January"), 42736);
64+assertEquals(DATEVALUE("2017, January"), 42736);
65+// Comma delimiters should be followed by spaces.
66+catchAndAssertEquals(function() {
67+ DATEVALUE("2017,January");
68+}, ERRORS.VALUE_ERROR);
69
70
71