spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[TODAY] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-04-27 02:00:00
stats
3 file(s) changed, 34 insertions(+), 5 deletions(-)
files
src/RawFormulas/Date.ts
src/RawFormulas/RawFormulas.ts
tests/DateFormulasTestTimeOverride.ts
  1diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
  2index 4fc2a5e..aa9a509 100644
  3--- a/src/RawFormulas/Date.ts
  4+++ b/src/RawFormulas/Date.ts
  5@@ -779,11 +779,20 @@ var NOW = function (...values) : ExcelDate {
  6   return new ExcelDate(moment());
  7 };
  8 
  9+/**
 10+ * Returns the current date as a date value.
 11+ * @returns {ExcelDate} today
 12+ * @constructor
 13+ */
 14+var TODAY = function (...values) {
 15+  ArgsChecker.checkLength(values, 0);
 16+  return new ExcelDate(moment().startOf("day"));
 17+};
 18+
 19 
 20 // Functions unimplemented.
 21 var WORKDAY$INTL;
 22 var TIME;
 23-var TODAY;
 24 var WORKDAY;
 25 
 26 export {
 27@@ -806,5 +815,6 @@ export {
 28   SECOND,
 29   NETWORKDAYS,
 30   NETWORKDAYS$INTL,
 31-  NOW
 32+  NOW,
 33+  TODAY
 34 }
 35\ No newline at end of file
 36diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
 37index 0da8087..c0d2a4e 100644
 38--- a/src/RawFormulas/RawFormulas.ts
 39+++ b/src/RawFormulas/RawFormulas.ts
 40@@ -128,7 +128,8 @@ import {
 41   SECOND,
 42   NETWORKDAYS,
 43   NETWORKDAYS$INTL,
 44-  NOW
 45+  NOW,
 46+  TODAY
 47 } from "./Date"
 48 
 49 var ACCRINT = Formula["ACCRINT"];
 50@@ -260,5 +261,6 @@ export {
 51   SECOND,
 52   NETWORKDAYS,
 53   NETWORKDAYS$INTL,
 54-  NOW
 55+  NOW,
 56+  TODAY
 57 }
 58\ No newline at end of file
 59diff --git a/tests/DateFormulasTestTimeOverride.ts b/tests/DateFormulasTestTimeOverride.ts
 60index 960f28a..7d12090 100644
 61--- a/tests/DateFormulasTestTimeOverride.ts
 62+++ b/tests/DateFormulasTestTimeOverride.ts
 63@@ -1,7 +1,8 @@
 64 
 65 import {
 66   NOW,
 67-  DATEVALUE
 68+  DATEVALUE,
 69+  TODAY
 70 } from "../src/RawFormulas/RawFormulas"
 71 import * as ERRORS from "../src/Errors"
 72 import {
 73@@ -22,6 +23,7 @@ function lockDate(year, month, day, hour, minute, second) {
 74   };
 75 }
 76 
 77+// Test NOW
 78 lockDate(2012, 11, 10, 4, 55, 4);
 79 assertEquals(NOW().toNumber(), DATEVALUE("Dec 10 2012"));
 80 lockDate(1999, 11, 10, 4, 55, 4);
 81@@ -32,4 +34,18 @@ lockDate(1944, 1, 2, 1, 11, 55);
 82 assertEquals(NOW().toNumber(), DATEVALUE("Feb 2 1944"));
 83 catchAndAssertEquals(function() {
 84   NOW(12);
 85+}, ERRORS.NA_ERROR);
 86+
 87+
 88+// Test TODAY
 89+lockDate(2012, 11, 10, 4, 55, 4);
 90+assertEquals(TODAY().toNumber(), DATEVALUE("Dec 10 2012"));
 91+lockDate(1999, 11, 10, 4, 55, 4);
 92+assertEquals(TODAY().toNumber(), DATEVALUE("Dec 10 1999"));
 93+lockDate(1999, 9, 22, 4, 55, 4);
 94+assertEquals(TODAY().toNumber(), DATEVALUE("Oct 22 1999"));
 95+lockDate(1944, 1, 2, 1, 11, 55);
 96+assertEquals(TODAY().toNumber(), DATEVALUE("Feb 2 1944"));
 97+catchAndAssertEquals(function() {
 98+  TODAY(12);
 99 }, ERRORS.NA_ERROR);
100\ No newline at end of file