spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[MINUTE,README.md] formula added and tested, adding TODOs
author
Ben Vogt <[email protected]>
date
2017-04-19 01:33:49
stats
4 file(s) changed, 77 insertions(+), 13 deletions(-)
files
README.md
src/RawFormulas/Date.ts
src/RawFormulas/RawFormulas.ts
tests/DateFormulasTest.ts
  1diff --git a/README.md b/README.md
  2index a02f0b6..502e758 100644
  3--- a/README.md
  4+++ b/README.md
  5@@ -11,10 +11,7 @@ And the same for MAX, MAXA, COUNT, COUNTA, etc. Look these over.
  6 
  7 ### Document the functions pulled in from jStat.
  8 
  9-### Bring back missing Excel functions
 10-* COVARIANCEP
 11-* COVARIANCES
 12-* ...etc.
 13+### Double check all relevant formulas from MSExcel and GS have been implemented.
 14 
 15 ### Refactor the way tests are organized.
 16 Group by error type and have some useful functions that will call with 0, N, N+1 args to test the args
 17@@ -29,23 +26,27 @@ Although dollar functions look like they just format `number`s, it seems like th
 18 This means that we should do dollar->number casting in all casting functions. For now, just using number primitive.
 19 See `DOLLAR` function for more info.
 20 
 21+### Get a better way to tie formulas into single export
 22+Listing them inside RawFormulas.ts is unwieldy.
 23 
 24+### Use `arguments` instead of `...values` for performance reasons.
 25 
 26-# The Great Date Refactoring (TM)
 27+### Error formatting
 28+Pass name of calling formula into all functions that throw user-facing errors, or have some sort of error mapper.
 29 
 30-* Dates have special types
 31+### Dates have special types
 32 Like dollars, dates are special types, but can be compared as if they're primatives. For example, this statement is
 33 valid inside a cell: `=DATE(1992, 6, 6) > =DATE(1992, 6, 10)`. We should check types and and have Date-to-number
 34 conversion inside parser.js.
 35 
 36-* Test all ExcelDate functions
 37+### Test all ExcelDate functions
 38 Right now we're just using the number of days since 1900, but we should check the other functions.
 39 
 40-* Verify that all N-times ({2,9}) are correct, and we're not parsing numbers too big.
 41+### Verify that all N-times ({2,9}) are correct, and we're not parsing numbers too big.
 42 
 43 
 44 
 45-# Testing Guidelines
 46+## Testing Guidelines
 47 
 48 All formulas should test for:
 49 1) One *less* argument than the formula expects, and one *more* argument than the formula expects.
 50diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
 51index eb343b5..8621ce3 100644
 52--- a/src/RawFormulas/Date.ts
 53+++ b/src/RawFormulas/Date.ts
 54@@ -569,9 +569,25 @@ var HOUR = function (...values) : number {
 55 };
 56 
 57 
 58+/**
 59+ * Returns the minute component of a specific time, in numeric format.
 60+ * @param values[0] time - The time from which to calculate the minute component. Must be a reference to a cell
 61+ * containing a date/time, a function returning a date/time type, or a number.
 62+ * @returns {number} minute of the time passed in.
 63+ * @constructor
 64+ */
 65+var MINUTE = function (...values) {
 66+  ArgsChecker.checkLength(values, 1);
 67+  var time = TypeCaster.firstValueAsTimestampNumber(values[0]);
 68+  if (time % 1 === 0) {
 69+    return 0;
 70+  }
 71+  var m = moment.utc([1900]).add(time * MILLISECONDS_IN_DAY, "milliseconds");
 72+  return m.minute();
 73+};
 74+
 75 
 76 // Functions unimplemented.
 77-var MINUTE;
 78 var NETWORKDAYS;
 79 var __COMPLEX_ITL = {
 80   "NETWORKDAYS.ITL": function () {},
 81@@ -598,5 +614,6 @@ export {
 82   WEEKNUM,
 83   YEARFRAC,
 84   TIMEVALUE,
 85-  HOUR
 86+  HOUR,
 87+  MINUTE
 88 }
 89\ No newline at end of file
 90diff --git a/src/RawFormulas/RawFormulas.ts b/src/RawFormulas/RawFormulas.ts
 91index 053df62..05aaf13 100644
 92--- a/src/RawFormulas/RawFormulas.ts
 93+++ b/src/RawFormulas/RawFormulas.ts
 94@@ -123,7 +123,8 @@ import {
 95   WEEKNUM,
 96   YEARFRAC,
 97   TIMEVALUE,
 98-  HOUR
 99+  HOUR,
100+  MINUTE
101 } from "./Date"
102 
103 var ACCRINT = Formula["ACCRINT"];
104@@ -250,5 +251,6 @@ export {
105   WEEKNUM,
106   DATEDIF,
107   TIMEVALUE,
108-  HOUR
109+  HOUR,
110+  MINUTE
111 }
112\ No newline at end of file
113diff --git a/tests/DateFormulasTest.ts b/tests/DateFormulasTest.ts
114index c831de7..0be98f0 100644
115--- a/tests/DateFormulasTest.ts
116+++ b/tests/DateFormulasTest.ts
117@@ -14,7 +14,8 @@ import {
118   WEEKNUM,
119   YEARFRAC,
120   TIMEVALUE,
121-  HOUR
122+  HOUR,
123+  MINUTE
124 } from "../src/RawFormulas/RawFormulas"
125 import * as ERRORS from "../src/Errors"
126 import {assertEquals} from "./utils/Asserts"
127@@ -35,6 +36,47 @@ function catchAndAssertEquals(toExecute, expected) {
128   }
129 }
130 
131+// Test MINUTE
132+assertEquals(MINUTE("8:10"), 10);
133+assertEquals(MINUTE("8:11"), 11);
134+assertEquals(MINUTE("8:44"), 44);
135+assertEquals(MINUTE("8:70"), 10);
136+assertEquals(MINUTE("8:120"), 0);
137+assertEquals(MINUTE("8:10000pm"), 40);
138+assertEquals(MINUTE("28:10000"), 40);
139+assertEquals(MINUTE("14:23232:9999991"), 58);
140+assertEquals(MINUTE(["8:10"]), 10);
141+assertEquals(MINUTE("11:21222:2111pm"), 17);
142+assertEquals(MINUTE("11:21222:2111am"), 17);
143+assertEquals(MINUTE(""), 0);
144+assertEquals(MINUTE(0), 0);
145+assertEquals(MINUTE(1), 0);
146+assertEquals(MINUTE(false), 0);
147+assertEquals(MINUTE(true), 0);
148+assertEquals(MINUTE(0.8), 12);
149+assertEquals(MINUTE(0.5), 0);
150+assertEquals(MINUTE(0.25), 0);
151+assertEquals(MINUTE(0.125), 0);
152+assertEquals(MINUTE(0.0625), 30);
153+assertEquals(MINUTE(1.5), 0);
154+assertEquals(MINUTE(99.5), 0);
155+assertEquals(MINUTE("1969-7-6 5:05am"), 5);
156+catchAndAssertEquals(function() {
157+  MINUTE("8:10", 5);
158+}, ERRORS.NA_ERROR);
159+catchAndAssertEquals(function() {
160+  MINUTE();
161+}, ERRORS.NA_ERROR);
162+catchAndAssertEquals(function() {
163+  MINUTE("str");
164+}, ERRORS.VALUE_ERROR);
165+catchAndAssertEquals(function() {
166+  MINUTE(" ");
167+}, ERRORS.VALUE_ERROR);
168+catchAndAssertEquals(function() {
169+  MINUTE([]);
170+}, ERRORS.REF_ERROR);
171+
172 
173 // Test HOUR
174 assertEquals(HOUR("8:10"), 8);