spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Starting work on DATEVALUE, adding TODOs to README.md
author
Ben Vogt <[email protected]>
date
2017-02-26 18:44:42
stats
2 file(s) changed, 23 insertions(+), 2 deletions(-)
files
README.md
src/RawFormulas/Date.ts
 1diff --git a/README.md b/README.md
 2index 7c73055..2ff49f6 100644
 3--- a/README.md
 4+++ b/README.md
 5@@ -52,4 +52,9 @@ Either through `arguments`, or directly passed in like `mean("FORMULA", [10, 20,
 6 ### Dollar functions have special types
 7 Although dollar functions look like they just format `number`s, it seems like they have a special type under the hood.
 8 This means that we should do dollar->number casting in all casting functions. For now, just using number primitive.
 9-See `DOLLAR` function for more info.
10\ No newline at end of file
11+See `DOLLAR` function for more info.
12+
13+### Dates have special types
14+Like dollars, dates are special types, but can be compared as if they're primatives. For example, this statement is
15+valid inside a cell: `=DATE(1992, 6, 6) > =DATE(1992, 6, 10)`. We should check types and and have Date-to-number
16+conversion inside parser.js.
17diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
18index 71fefe9..fe2f448 100644
19--- a/src/RawFormulas/Date.ts
20+++ b/src/RawFormulas/Date.ts
21@@ -34,10 +34,25 @@ var DATE = function (...values) {
22 };
23 
24 
25-var DATEVALUE = function (dateString: string) : Date {
26-  return new Date(dateString);
27+/**
28+ * Converts a provided date string in a known format to a date value.
29+ * @param values[0] date_string - The string representing the date. Understood formats include any date format which is
30+ * normally autoconverted when entered, without quotation marks, directly into a cell. Understood formats may depend on
31+ * region and language settings. Examples include: "1/23/2012", "1/23/2012 8:10:30", "2012/1/23", "2012-1-23"
32+ * @returns {number}
33+ * @constructor
34+ */
35+var DATEVALUE = function (...values) : number {
36+  ArgsChecker.checkLength(values, 1);
37+  var dateNumber = new ExcelDate(moment()).toNumber();
38+  if (dateNumber < 0) {
39+    throw new CellError(NUM_ERROR, "DATEVALUE evaluates to an out of range value " + dateNumber
40+      + ". It should be greater than or equal to 0.");
41+  }
42+  return dateNumber;
43 };
44 
45+
46 var DAY = Formula["DAY"];
47 var DAYS = Formula["DAYS"];
48 var DAYS360 = Formula["DAYS360"];