spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
EDATE formula tested and working
author
Ben Vogt <[email protected]>
date
2017-04-02 17:09:14
stats
2 file(s) changed, 13 insertions(+), 1 deletions(-)
files
src/RawFormulas/Date.ts
tests/DateFormulasTest.ts
 1diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
 2index 8469e8d..e01db5b 100644
 3--- a/src/RawFormulas/Date.ts
 4+++ b/src/RawFormulas/Date.ts
 5@@ -340,10 +340,19 @@ var DATEVALUE = function (...values) : number {
 6 };
 7 
 8 
 9+/**
10+ * Returns a date a specified number of months before or after another date.
11+ * @param values[0] start_date - The date from which to calculate the result.
12+ * @param values[1] months - The number of months before (negative) or after (positive) start_date to calculate.
13+ * @returns {ExcelDate} date a specified number of months before or after another date
14+ * @constructor
15+ */
16 var EDATE = function (...values) : ExcelDate {
17   ArgsChecker.checkLength(values, 2);
18   var startDate = TypeCaster.firstValueAsExcelDate(values[0]);
19-  var months = TypeCaster.firstValueAsNumber(values[1]);
20+  var months = Math.floor(TypeCaster.firstValueAsNumber(values[1]));
21+  // While ExcelDate.toNumber() will return an inclusive count of days since 1900/1/1, moment.Moment.add assumes
22+  // exclusive count of days.
23   return new ExcelDate(moment.utc(ORIGIN_MOMENT).add(startDate.toNumber() - 2, "days").add(months, "months"));
24 };
25 
26diff --git a/tests/DateFormulasTest.ts b/tests/DateFormulasTest.ts
27index 6bf5495..6fc08c0 100644
28--- a/tests/DateFormulasTest.ts
29+++ b/tests/DateFormulasTest.ts
30@@ -22,6 +22,7 @@ function catchAndAssertEquals(toExecute, expected) {
31 // // Test EDATE
32 assertEquals(EDATE(DATE(1992, 6, 24), 1), DATE(1992, 7, 24));
33 assertEquals(EDATE(DATE(1992, 5, 24), 2), DATE(1992, 7, 24));
34+assertEquals(EDATE(DATE(1992, 5, 24), 2.2), DATE(1992, 7, 24));
35 
36 
37 // Test DATE
38@@ -36,6 +37,7 @@ catchAndAssertEquals(function() {
39 }, ERRORS.NUM_ERROR);
40 assertEquals(DATE(1992, 6, 24).toNumber(), 33779);
41 assertEquals(DATE(2017, 2, 26).toNumber(), 42792);
42+assertEquals(DATE(1999, 1, 13).toNumber(), 36173);
43 // Leap day stuff
44 assertEquals(DATE(2004, 2, 28).toNumber(), 38045);
45 assertEquals(DATE(2004, 2, 29).toNumber(), 38046);