spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Cleaning up README.md, documentation.
author
Ben Vogt <[email protected]>
date
2017-04-01 22:06:20
stats
3 file(s) changed, 4 insertions(+), 79 deletions(-)
files
README.md
src/RawFormulas/Date.ts
src/RawFormulas/Utils.ts
  1diff --git a/README.md b/README.md
  2index 5cc7d77..16fcac7 100644
  3--- a/README.md
  4+++ b/README.md
  5@@ -51,68 +51,9 @@ See `DOLLAR` function for more info.
  6 
  7 
  8 # The Great Date Refactoring (TM)
  9-### Different Date Formats
 10-```
 11-FORMAT           CONST NAME                              ACCESS ORDER
 12-YYYY/MM/DD       YEAR_MONTHDIG_DAY_SLASH_DELIMIT         years, months, days
 13-YYYY-MM-DD       YEAR_MONTHDIG_DAY_HYPHEN_DELIMIT        years, months, days
 14-YYYY.MM.DD       YEAR_MONTHDIG_DAY_DOT_DELIMIT           years, months, days
 15-YYYY MM DD       YEAR_MONTHDIG_DAY_SPACE_DELIMIT         years, months, days
 16-YYYY, MM, DD     YEAR_MONTHDIG_DAY_COMMA_DELIMIT         years, months, days
 17-MM/DD/YYYY       MONTHDIG_DAY_YEAR_SLASH_DELIMIT         months, days, years
 18-MM-DD-YYYY       MONTHDIG_DAY_YEAR_HYPHEN_DELIMIT        months, days, years
 19-MM.DD.YYYY       MONTHDIG_DAY_YEAR_DOT_DELIMIT           months, days, years
 20-MM DD YYYY       MONTHDIG_DAY_YEAR_SPACE_DELIMIT         months, days, years
 21-MM, DD, YYYY     MONTHDIG_DAY_YEAR_COMMA_DELIMIT         months, days, years
 22-Month DD YYYY    MONTHNAME_DAY_YEAR_COMMON_DELIMITERS    monthName, days, years        // TODO: right now only comma...
 23-DD Month YYYY    DAY_MONTHNAME_YEAR_COMMON_DELIMITERS    days, monthName, years        // TODO: right now only comma...
 24-Month DD         MONTHNAME_DAY_COMMON_DELIMITERS         monthName, days
 25-DD Month         DAY_MONTHNAME_COMMON_DELIMITERS         days, monthName
 26-Month YYYY       MONTHNAME_YEAR_COMMON_DELIMITERS        monthName, years              // TODO: only some delimiters now
 27-YYYY Month       YEAR_MONTHNAME_COMMON_DELIMITERS        years, monthName
 28-MM/DD            MONTHDIG_DAY_SLASH_DELIMIT              months, days
 29-MM-DD            MONTHDIG_DAY_HYPHEN_DELIMIT             months, days
 30-MM DD            MONTHDIG_DAY_SPACE_DELIMIT              months, days
 31-MM.DD            MONTHDIG_DAY_DOT_DELIMIT                months, days
 32-MM, DD           MONTHDIG_DAY_COMMA_DELIMIT              months, days
 33-MM/YYYY          MONTHDIG_YEAR_SLASH_DELIMIT             months, years
 34-MM-YYYY          MONTHDIG_YEAR_HYPHEN_DELIMIT            months, years
 35-MM YYYY          MONTHDIG_YEAR_SPACE_DELIMIT             months, years
 36-MM.YYYY          MONTHDIG_YEAR_DOT_DELIMIT               months, years
 37-MM, YYYY         MONTHDIG_YEAR_COMMA_DELIMIT             months, years
 38-```
 39-
 40-### Different Time Formats
 41-```
 42-FORMAT           CONST NAME
 43-HHam             HOUR_MERIDIEM
 44-HH:MM            OVERFLOW_HOURS_OVERFLOW_MINUTES
 45-HH:MMam          HOURS_OVERFLOW_MINUTES_MERIDIEM
 46-HH:MM:SS         OVERFLOW_HOURS_OVERFLOW_MINUTES_SECONDS
 47-HH:MM:SSam       HOURS_MINUTES_SECONDS_OVERFLOW_MERIDIEM
 48-```
 49-
 50-### Condensed Date Formats
 51-```
 52-NOTES
 53-fd = flex_delimitor
 54-all can be prefixed with day name (no op)
 55-all can be suffixed with time (yes op)
 56-
 57-YYYY(fd)MM(fd)DD          YEAR_MONTHDIG_DAY
 58-MM(fd)DD(fd)YYYY          MONTHDIG_DAY_YEAR
 59-Month(fd)DD(fd)YYYY       MONTHNAME_DAY_YEAR
 60-DD(fd)Month(fd)YYYY       DAY_MONTHNAME_YEAR
 61-YYYY(fd)MM                YEAR_MONTHDIG
 62-MM(fd)YYYY                MONTHDIG_YEAR
 63-YYYY(fd)Month             YEAR_MONTHNAME
 64-Month(fd)YYYY             MONTHNAME_YEAR
 65-```
 66-Capture the flex delimiter and invalidate if the three don't match.
 67-
 68 
 69 ### List of possible dates that we should be able to parse
 70-* "1999/1/13"                    DONE
 71+ * "1999/1/13"                    DONE
 72  * "1999-1-13"
 73  * "1999 1 13"
 74  * "1999.1.13"
 75@@ -191,13 +132,6 @@ Capture the flex delimiter and invalidate if the three don't match.
 76  * "10-2022 10:10:10"
 77  * "10-2022 10:10:10pm"
 78 
 79-
 80-* Combine the different time formats into a single regular expression.
 81-Throw errors based on whether some units have overflowed. For example 29:99 is ok, but 29:99pm is not ok. This way
 82-we're only doubling the number of date-format regular expressions we have to generate. For example, we check
 83-YEAR_MONTHDIG_DAY_SLASH_DELIMIT once, and then YEAR_MONTHDIG_DAY_SLASH_DELIMIT_WITH_TIME once.
 84-Use something like this: https://regex101.com/r/ZMu74e/2
 85-
 86 * Dates have special types
 87 Like dollars, dates are special types, but can be compared as if they're primatives. For example, this statement is
 88 valid inside a cell: `=DATE(1992, 6, 6) > =DATE(1992, 6, 10)`. We should check types and and have Date-to-number
 89@@ -209,15 +143,6 @@ Annotate them, and standardize the error checking for errors like REF, NA, NUM,
 90 * Test all ExcelDate functions
 91 Right now we're just using the number of days since 1900, but we should check the other functions.
 92 
 93-* YYYY/MM/DD HH:mm needs more thurough testing
 94-
 95 * Verify that all white-space wild cards are implemented properly
 96 
 97 * Verify that all N-times ({2,9}) are correct, and we're not parsing numbers too big.
 98-
 99-* Many times I use `\s*` when I actaully mean `\s+`
100-Or the are times when I mean "Feb 20 2019" or "Feb 20,2019", and either is correct.
101-
102-* Use `startOf('year')` to zero out all dates before building them up.
103-No current tests should change because of this but it should eliminate some edge cases.
104-
105diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
106index 362b159..2df88a1 100644
107--- a/src/RawFormulas/Date.ts
108+++ b/src/RawFormulas/Date.ts
109@@ -25,12 +25,12 @@ import {
110  */
111 var DATE = function (...values) {
112   const FIRST_YEAR = 1900;
113-  const ORIGIN_DATE = moment.utc([FIRST_YEAR]);
114+  const ORIGIN_DATE = moment.utc([FIRST_YEAR]).startOf("year");
115   ArgsChecker.checkLength(values, 3);
116   var year = Math.abs(Math.floor(TypeCaster.firstValueAsNumber(values[0]))); // No negative values for year
117   var month = Math.floor(TypeCaster.firstValueAsNumber(values[1])) - 1; // Months are between 0 and 11.
118   var day = Math.floor(TypeCaster.firstValueAsNumber(values[2])) - 1; // Days are also zero-indexed.
119-  var m = moment.utc(ORIGIN_DATE)
120+  var m = moment.utc(ORIGIN_DATE).startOf("year")
121       .add(year < FIRST_YEAR ? year : year - FIRST_YEAR, 'years') // If the value is less than 1900, assume 1900 as start index for year
122       .add(month, 'months')
123       .add(day, 'days');
124diff --git a/src/RawFormulas/Utils.ts b/src/RawFormulas/Utils.ts
125index 767b26f..0f4ff31 100644
126--- a/src/RawFormulas/Utils.ts
127+++ b/src/RawFormulas/Utils.ts
128@@ -524,6 +524,7 @@ class DateRegExBuilder {
129   /**
130    * Add capture group for a flexible delimiter, including ", ", " ", ".", "\", "-". Different from FLEX_DELIMITER
131    * in that it will match periods with zero or more spaces on either side.
132+   * For reference: https://regex101.com/r/q1fp1z/1/
133    * @returns {DateRegExBuilder} builder
134    * @constructor
135    */