spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Implementing and testing some date-based formulas
author
Ben Vogt <[email protected]>
date
2017-01-08 00:19:34
stats
2 file(s) changed, 11 insertions(+), 7 deletions(-)
files
src/SupportedFormulas.ts
tests/SheetFormulaTest.ts
 1diff --git a/src/SupportedFormulas.ts b/src/SupportedFormulas.ts
 2index 350368f..79eff7c 100644
 3--- a/src/SupportedFormulas.ts
 4+++ b/src/SupportedFormulas.ts
 5@@ -19,6 +19,9 @@ const SUPPORTED_FORMULAS = [
 6 const OverrideFormulas = {
 7   ATAN2: function (x, y) {
 8     return Math.atan2(y, x);
 9+  },
10+  DATEVALUE: function (dateString: string) : Date {
11+    return new Date(dateString);
12   }
13 };
14 
15diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
16index 63ff140..c58034f 100644
17--- a/tests/SheetFormulaTest.ts
18+++ b/tests/SheetFormulaTest.ts
19@@ -9,7 +9,7 @@ function testFormula(formula: string, expectation: any) {
20   assertEquals(expectation, cell.getValue());
21 }
22 
23-function testFormulaDate(formula: string, expectation: any) {
24+function testFormulaToDate(formula: string, expectation: any) {
25   var sheet  = new Sheet();
26   sheet.setCell("A1", formula);
27   var cell = sheet.getCell("A1");
28@@ -238,20 +238,19 @@ testFormula("=CUMIPMT(0.12, 12, 100, 1, 5, 0)", -54.39423242396348);
29 testFormula("=CUMPRINC(0.12, 12, 100, 1, 5, 0)", -26.324171373034403);
30 
31 // Test DATE
32-testFormulaDate("=DATE(1992, 6, 24)", new Date("6/24/1992").getTime());
33+testFormulaToDate("=DATE(1992, 6, 24)", new Date("6/24/1992").getTime());
34 
35 // Test DATEVALUE
36-// TODO: DATEVALUE should work.
37-// testFormula('=DATEVALUE("1992-6-24")', 33779);
38+testFormulaToDate('=DATEVALUE("1992-6-24")', new Date("6/24/1992").getTime());
39 
40 // Test DAY
41-// TODO: This should work
42+testFormula('=DAY(DATEVALUE("1992-6-24"))', 24);
43 
44 // Test DAYS
45-// TODO: This should work
46+testFormula('=DAYS(DATEVALUE("1993-6-24"), DATEVALUE("1992-6-24"))', 365);
47 
48 // Test DAYS360
49-// TODO: This should work
50+testFormula('=DAYS360(DATE(1969, 7, 16), DATE(1970, 7, 24), 1)', 368);
51 
52 // Test DB
53 testFormula("=DB(100, 50, 10, 2, 12)", 6.2511);