commit
message
Taking a step backwards to build up to the more complex regular expressions
author
Ben Vogt <[email protected]>
date
2017-03-27 01:39:38
stats
2 file(s) changed,
2 insertions(+),
42 deletions(-)
files
src/RawFormulas/Date.ts
tests/DateFormulasTest.ts
1diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
2index 625a23e..3ee3667 100644
3--- a/src/RawFormulas/Date.ts
4+++ b/src/RawFormulas/Date.ts
5@@ -439,21 +439,10 @@ var DATEVALUE = function (...values) : number {
6 }
7 }
8
9- // Check DD Month (Year)
10+ // Check DD Month
11 if (m === undefined) {
12 // For reference: https://regex101.com/r/mOnd0i/4
13- var matches = dateString.match(/^\s*(0?[1-9]|[1-2][0-9]|3[0-1])(,?\s*|\s*-?\/?\s*|\s*\.?\s+)(january|february|march|april|may|june|july|august|september|october|november|december|jan|feb|mar|apr|jun|jul|aug|sep|oct|nov|dec)\s*,?\s*\/?\s*(\.?\s+)?([0-9]{4}|[1-9][0-9]{2}|[0-9]{2})?$/i);
14- if (matches && (matches.length >= 4 || matches.length <= 6)) {
15- var monthName = matches[3];
16- var days = parseInt(matches[1]) - 1; // Days are zero indexed.
17- var year = matches.length === 5 ? moment.utc().year() : parseInt(matches[5]);
18- var tmpMoment = moment.utc([year]).startOf('year').month(monthName);
19- // If we're specifying more days than there are in this month
20- if (days > tmpMoment.daysInMonth() - 1) {
21- throw new CellError(VALUE_ERROR, "DATEVALUE parameter '" + dateString + "' cannot be parsed to date/time.");
22- }
23- m = tmpMoment.add({"days": days});
24- }
25+ // Code here.
26 }
27
28 // Check Month DD
29diff --git a/tests/DateFormulasTest.ts b/tests/DateFormulasTest.ts
30index a2d0104..318f5fd 100644
31--- a/tests/DateFormulasTest.ts
32+++ b/tests/DateFormulasTest.ts
33@@ -378,7 +378,7 @@ catchAndAssertEquals(function() {
34 catchAndAssertEquals(function() {
35 DATEVALUE("Dec.20");// need space if using period
36 }, ERRORS.VALUE_ERROR);
37-// DD Month
38+// DD Month YYYY
39 assertEquals(DATEVALUE("01 Jan 2017"), 42736);
40 assertEquals(DATEVALUE("01 Feb 2017"), 42767);
41 assertEquals(DATEVALUE("01 Mar 2017"), 42795);
42@@ -403,30 +403,3 @@ assertEquals(DATEVALUE("20 Sep 2015"), 42267);
43 assertEquals(DATEVALUE("20 Oct 2015"), 42297);
44 assertEquals(DATEVALUE("20 Nov 2015"), 42328);
45 assertEquals(DATEVALUE("20 Dec 2015"), 42358);
46-assertEquals(DATEVALUE("20. Dec 2015"), 42358);
47-assertEquals(DATEVALUE("20, Dec 2015"), 42358);
48-assertEquals(DATEVALUE("20/ Dec 2015"), 42358);
49-assertEquals(DATEVALUE("20- Dec 2015"), 42358);
50-assertEquals(DATEVALUE("20-Dec 2015"), 42358);
51-assertEquals(DATEVALUE("2 June 2015"), 42157);
52-assertEquals(DATEVALUE("2 / june 2015"), 42157);
53-assertEquals(DATEVALUE("2 . june . 2015"), 42157);
54-assertEquals(DATEVALUE("2, june 2015"), 42157);
55-assertEquals(DATEVALUE("2, june2015"), 42157);
56-assertEquals(DATEVALUE("2,June2015"), 42157);
57-assertEquals(DATEVALUE("2June2015"), 42157);
58-assertEquals(DATEVALUE("2. June. 2015"), 42157);
59-assertEquals(DATEVALUE("2/June/2015"), 42157);
60-assertEquals(DATEVALUE("2 /June / 2015"), 42157);
61-catchAndAssertEquals(function() {
62- DATEVALUE("20.Dec 2015");// need space if using period
63-}, ERRORS.VALUE_ERROR);
64-catchAndAssertEquals(function() {
65- DATEVALUE("20.Dec.2015");// need space if using period
66-}, ERRORS.VALUE_ERROR);
67-catchAndAssertEquals(function() {
68- DATEVALUE("20 Dec.2015");// need space if using period
69-}, ERRORS.VALUE_ERROR);
70-catchAndAssertEquals(function() {
71- DATEVALUE("20.Dec");// need space if using period
72-}, ERRORS.VALUE_ERROR);