spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[ExcelTime, TIME, README.md] Documenting how types are compared and displayed.
author
Ben Vogt <[email protected]>
date
2017-04-27 03:06:30
stats
3 file(s) changed, 26 insertions(+), 3 deletions(-)
files
README.md
src/ExcelTime.ts
src/RawFormulas/Date.ts
 1diff --git a/README.md b/README.md
 2index 55d103f..1dc0ecd 100644
 3--- a/README.md
 4+++ b/README.md
 5@@ -7,7 +7,8 @@ Things I should do.
 6 ### SUM and SUMA should be different, and I'm pretty sure they're currently the same.
 7 And the same for MAX, MAXA, COUNT, COUNTA, etc. Look these over.
 8 
 9-### Criteria evaluations should escape reg-ex characters: http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
10+### Criteria evaluations should escape reg-ex characters
11+http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
12 
13 ### Document the functions pulled in from jStat.
14 
15@@ -35,9 +36,17 @@ Listing them inside RawFormulas.ts is unwieldy.
16 Pass name of calling formula into all functions that throw user-facing errors, or have some sort of error mapper.
17 
18 ### Dates have special types
19-Like dollars, dates are special types, but can be compared as if they're primitives. For example, this statement is
20+* Like dollars, dates are special types, but can be compared as if they're primitives. For example, this statement is
21 valid inside a cell: `=DATE(1992, 6, 6) > =DATE(1992, 6, 10)`. We should check types and and have Date-to-number
22 conversion inside parser.js.
23+* The same rule applies for time-types. It seems like under the hood, times are represented using a number between
24+0 and 1, exclusive on the end. When comparing them, this: `=TIME(12, 0, 0) = 0.5` evaluates to TRUE, and
25+`=TIME(12, 0, 0) <> 0.5` evaluates to FALSE.
26+* Furthermore, it appears that Cells themselves have types. If a cell contains `=TIME(12, 0, 0) + 0.1`, the result will
27+not be displayed as a decimal, but instead as a time, eg: "1:12:00 AM". However, you can force the application to display it as
28+a different type.
29+* The automatic display type for a Cell seems to be inherited from it's most complex type: [ExcelDate, ExcelTime,
30+number, boolean, string].
31 
32 ### Test all ExcelDate functions
33 Right now we're just using the number of days since 1900, but we should check the other functions.
34diff --git a/src/ExcelTime.ts b/src/ExcelTime.ts
35index 2f3a8cb..cf82082 100644
36--- a/src/ExcelTime.ts
37+++ b/src/ExcelTime.ts
38@@ -42,4 +42,8 @@ class ExcelTime {
39     return other.toNumber() === this.toNumber();
40   }
41 
42+}
43+
44+export {
45+  ExcelTime
46 }
47\ No newline at end of file
48diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
49index b440e2c..d3babe6 100644
50--- a/src/RawFormulas/Date.ts
51+++ b/src/RawFormulas/Date.ts
52@@ -13,6 +13,9 @@ import {
53   ExcelDate,
54   ORIGIN_MOMENT
55 } from "../ExcelDate";
56+import {
57+  ExcelTime
58+} from "../ExcelTime";
59 
60 /**
61  * Converts a provided year, month, and day into a date.
62@@ -790,11 +793,18 @@ var TODAY = function (...values) {
63 };
64 
65 
66-var TIME = function (...values) {
67+/**
68+ *
69+ * @param values
70+ * @returns {ExcelTime}
71+ * @constructor
72+ */
73+var TIME = function (...values) : ExcelTime {
74   ArgsChecker.checkLength(values, 3);
75   var hours = Math.abs(Math.floor(TypeCaster.firstValueAsNumber(values[0])));
76   var minutes = Math.floor(TypeCaster.firstValueAsNumber(values[1])) - 1;
77   var seconds = Math.floor(TypeCaster.firstValueAsNumber(values[2])) - 1;
78+  return new ExcelTime(hours, minutes, seconds);
79 };
80 
81