spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Adding more tests for minute-overflow, because I am nervous about it.
author
Ben Vogt <[email protected]>
date
2017-03-12 19:35:24
stats
4 file(s) changed, 22 insertions(+), 11 deletions(-)
files
README.md
src/ExcelDate.ts
src/RawFormulas/Date.ts
tests/FormulasTest.ts
  1diff --git a/README.md b/README.md
  2index b8a7482..606eaca 100644
  3--- a/README.md
  4+++ b/README.md
  5@@ -48,13 +48,18 @@ Although dollar functions look like they just format `number`s, it seems like th
  6 This means that we should do dollar->number casting in all casting functions. For now, just using number primitive.
  7 See `DOLLAR` function for more info.
  8 
  9-### Dates have special types
 10+### Date TODOS
 11+#### Dates have special types
 12 Like dollars, dates are special types, but can be compared as if they're primatives. For example, this statement is
 13 valid inside a cell: `=DATE(1992, 6, 6) > =DATE(1992, 6, 10)`. We should check types and and have Date-to-number
 14 conversion inside parser.js.
 15 
 16-### Organize tests in a way that makes sense.
 17+#### Organize tests in a way that makes sense.
 18 Annotate them, and standardize the error checking for errors like REF, NA, NUM, VALUE, etc.
 19 
 20-### Test all ExcelDate functions
 21-Right now we're just using the number of days since 1900, but we should check the other functions.
 22\ No newline at end of file
 23+#### Test all ExcelDate functions
 24+Right now we're just using the number of days since 1900, but we should check the other functions.
 25+
 26+#### YYYY/MM/DD HH:mm needs more thurough testing
 27+
 28+#### Verify that all white-space wild cards are implemented properly
 29\ No newline at end of file
 30diff --git a/src/ExcelDate.ts b/src/ExcelDate.ts
 31index 8613997..836bbd7 100644
 32--- a/src/ExcelDate.ts
 33+++ b/src/ExcelDate.ts
 34@@ -28,7 +28,7 @@ class ExcelDate {
 35    * @returns {string} day in the format M/D/YYYY.
 36    */
 37   toString() {
 38-    return ORIGIN_MOMENT.add(this.day, 'days').format("M/D/Y");
 39+    return moment.utc(ORIGIN_MOMENT).add(this.day, 'days').format("M/D/Y");
 40   }
 41 
 42   /**
 43diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
 44index e33bbd2..c9e1c25 100644
 45--- a/src/RawFormulas/Date.ts
 46+++ b/src/RawFormulas/Date.ts
 47@@ -49,9 +49,9 @@ var DATE = function (...values) {
 48  * region and language settings. Examples include:
 49  * "1999/1/13"              DONE
 50  * "1/13/1999"              DONE
 51- * "1999/1/13 10am"
 52- * "1999/1/13 10:22"
 53- * "1999/1/13 10:10am"
 54+ * "1999/1/13 10am"         DONE
 55+ * "1999/1/13 10:22"        DONE
 56+ * "1999/1/13 10:10am"      DONE
 57  * "1999/1/13 10:10:10"
 58  * "1999/1/13 10:10:10pm"
 59  * "Sun Feb 09 2017"
 60@@ -171,8 +171,8 @@ var DATEVALUE = function (...values) : number {
 61 
 62   // Check YYYY/MM/DD HH:mm(am|pm)
 63   if (m === undefined) {
 64-    // For reference: https://regex101.com/r/DMA4Fv/2
 65-    var matches = dateString.match(/^\s*(([0-9][0-9][0-9][0-9])|([1-9][0-9][0-9]))\/([1-9]|0[1-9]|1[0-2])\/([1-9]|[0-2][0-9]|3[0-1])\s*([0-9]|0[0-9]|1[0-2]):([0-9]+)\s*(am|pm)\s*$/i);
 66+    // For reference: https://regex101.com/r/DMA4Fv/3
 67+    var matches = dateString.match(/^\s*(([0-9][0-9][0-9][0-9])|([1-9][0-9][0-9]))\/([1-9]|0[1-9]|1[0-2])\/([1-9]|[0-2][0-9]|3[0-1])\s*([0-9]|0[0-9]|1[0-2]):\s*([0-9]+)\s*(am|pm)\s*$/i);
 68     if (matches && matches.length === 9) {
 69       var years = parseInt(matches[1]);
 70       var months = parseInt(matches[4]) - 1; // Months are zero indexed.
 71diff --git a/tests/FormulasTest.ts b/tests/FormulasTest.ts
 72index 3bc5104..7d9be9c 100644
 73--- a/tests/FormulasTest.ts
 74+++ b/tests/FormulasTest.ts
 75@@ -930,8 +930,8 @@ assertEquals(DATEVALUE("1999/1/01 02:59pm"), 36161);
 76 assertEquals(DATEVALUE("2222/1/01 03:33pm"), 117610);
 77 assertEquals(DATEVALUE("1902/9/02 12:33pm"), 976);
 78 assertEquals(DATEVALUE("1902/9/2 12:33pm"), 976);
 79-assertEquals(DATEVALUE("4243/11/3 12:33pm   "), 856071);
 80-assertEquals(DATEVALUE("  1992/04/19   12:33pm   "), 33713);
 81+assertEquals(DATEVALUE("4243/11/3 12:33pm"), 856071);
 82+assertEquals(DATEVALUE("  1992/04/19   12:  33pm   "), 33713);
 83 assertEquals(DATEVALUE("1992/5/20 01:33am"), 33744);
 84 assertEquals(DATEVALUE("1992/6/21  3:33pm"), 33776);
 85 assertEquals(DATEVALUE("1992/9/29 3:33pm"), 33876);
 86@@ -963,14 +963,17 @@ assertEquals(DATEVALUE("1992/1/13 12:720pm"), 33617); // overload minutes
 87 assertEquals(DATEVALUE("1992/1/13 00:720pm"), 33617); // overload minutes
 88 assertEquals(DATEVALUE("1992/1/13 12:719pm"), 33616); // overload minutes
 89 assertEquals(DATEVALUE("1992/1/13 00:720am"), 33616); // overload minutes
 90+assertEquals(DATEVALUE("1992/1/13 00:01pm"), 33616); // overload minutes
 91 assertEquals(DATEVALUE("1992/1/13 12:66669pm"), 33662); // overload minutes
 92 assertEquals(DATEVALUE("1992/1/13 12:66669am"), 33662); // overload minutes
 93 assertEquals(DATEVALUE("1992/1/13 12:66249pm"), 33662); // overload minutes
 94 assertEquals(DATEVALUE("1992/1/13 12:66249am"), 33662); // overload minutes
 95 assertEquals(DATEVALUE("1992/1/13 12:666669am"), 34078); // overload minutes
 96 assertEquals(DATEVALUE("1992/1/13 12:666669pm"), 34079); // overload minutes
 97-
 98-
 99+assertEquals(DATEVALUE("1992/1/13 12:100000000am"), 103060); // overload minutes
100+assertEquals(DATEVALUE("1992/1/13 12:0912347287am"), 667190); // overload minutes
101+assertEquals(DATEVALUE("1992/1/13 12:00000912347287am"), 667190); // overload minutes
102+assertEquals(DATEVALUE("1992/1/13 12:1989198298am"), 1415003); // overload minutes
103 
104 
105