commit
message
Using DateRegExBuilder for 'MONTHNAME_YEAR_COMMON_DELIMITERS, Month YYYY, June 2012'
author
Ben Vogt <[email protected]>
date
2017-03-27 00:31:12
stats
3 file(s) changed,
19 insertions(+),
2 deletions(-)
files
README.md
src/RawFormulas/Date.ts
src/RawFormulas/Utils.ts
1diff --git a/README.md b/README.md
2index 891aa01..1e2d4cc 100644
3--- a/README.md
4+++ b/README.md
5@@ -68,7 +68,7 @@ Month DD YYYY MONTHNAME_DAY_YEAR_COMMON_DELIMITERS monthName, days, years
6 DD Month YYYY DAY_MONTHNAME_YEAR_COMMON_DELIMITERS days, monthName, years // TODO: right now only comma...
7 Month DD MONTHNAME_DAY_COMMON_DELIMITERS monthName, days
8 DD Month DAY_MONTHNAME_COMMON_DELIMITERS days, monthName
9-Month YYYY MONTHNAME_YEAR_COMMON_DELIMITERS monthName, years
10+Month YYYY MONTHNAME_YEAR_COMMON_DELIMITERS monthName, years // TODO: only some delimiters now
11 YYYY Month YEAR_MONTHNAME_COMMON_DELIMITERS years, monthName
12 MM/DD MONTHDIG_DAY_SLASH_DELIMIT months, days
13 MM-DD MONTHDIG_DAY_HYPHEN_DELIMIT months, days
14diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
15index 4aaeb3f..625a23e 100644
16--- a/src/RawFormulas/Date.ts
17+++ b/src/RawFormulas/Date.ts
18@@ -417,10 +417,15 @@ var DATEVALUE = function (...values) : number {
19 }
20 }
21
22- // Check Month YYYY
23+ // Check MONTHNAME_YEAR_COMMON_DELIMITERS, Month YYYY, June 2012
24 if (m === undefined) {
25 // For reference: https://regex101.com/r/eNyVAL/3
26- var matches = dateString.match(/^\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*)([0-9]{4})\s*$/i);
27+ const REG = DateRegExBuilder.DateRegExBuilder()
28+ .start()
29+ .MONTHNAME().COMMON_DELIMITERS().YYYY_SIMPLE() // YYYY_SIMPLE necessary because we don't want collisions with DD.
30+ .end()
31+ .build();
32+ var matches = dateString.match(REG);
33 if (matches && matches.length === 4) {
34 var years = parseInt(matches[3]);
35 var monthName = matches[1];
36diff --git a/src/RawFormulas/Utils.ts b/src/RawFormulas/Utils.ts
37index a3fac88..4f3c02a 100644
38--- a/src/RawFormulas/Utils.ts
39+++ b/src/RawFormulas/Utils.ts
40@@ -461,6 +461,16 @@ class DateRegExBuilder {
41 return this;
42 }
43
44+ YYYY_SIMPLE() : DateRegExBuilder {
45+ this.regexString += "([0-9]{4})";
46+ return this;
47+ }
48+
49+ COMMON_DELIMITERS() : DateRegExBuilder {
50+ this.regexString += "(,?\\s*|\\s*-?\\.?-?\\/?\\s*)";
51+ return this;
52+ }
53+
54 /**
55 *
56 * @returns {DateRegExBuilder}