spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[WEEKNUM] formula added, tested and working
author
Ben Vogt <[email protected]>
date
2017-04-15 03:45:16
stats
2 file(s) changed, 23 insertions(+), 8 deletions(-)
files
src/RawFormulas/Date.ts
tests/DateFormulasTest.ts
 1diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
 2index 1550bae..988f4c0 100644
 3--- a/src/RawFormulas/Date.ts
 4+++ b/src/RawFormulas/Date.ts
 5@@ -272,6 +272,7 @@ var WEEKDAY = function (...values) {
 6  * the system used for determining the first week of the year (1=Sunday, 2=Monday).
 7  * @returns {number} representing week number of year.
 8  * @constructor
 9+ * TODO: The performance of this function could be improved.
10  */
11 var WEEKNUM = function (...values) {
12   ArgsChecker.checkLengthWithin(values, 1, 2);
13@@ -358,13 +359,6 @@ var WEEKNUM = function (...values) {
14   } else {
15     throw new NumError("Function WEEKNUM parameter 2 value " + shiftType + " is out of range.");
16   }
17-
18-
19-
20-  // var startOfYear = moment.utc(dm).startOf("year");
21-  // var dayOfWeekOfNewYearsDay = startOfYear.weekday();
22-  // var weekNum = 1;// let's start with the week being the first one, and walking it forward
23-  // var shiftedNewYearsDay = dayShift[dayOfWeekOfNewYearsDay];
24 };
25 
26 
27diff --git a/tests/DateFormulasTest.ts b/tests/DateFormulasTest.ts
28index 143eafb..80d0056 100644
29--- a/tests/DateFormulasTest.ts
30+++ b/tests/DateFormulasTest.ts
31@@ -553,7 +553,27 @@ assertEquals(WEEKNUM(743, 21), 2);
32 assertEquals(WEEKNUM(744, 21), 3);
33 assertEquals(WEEKNUM(745, 21), 3);
34 assertEquals(WEEKNUM(746, 21), 3);
35-
36+catchAndAssertEquals(function() {
37+  WEEKNUM();
38+}, ERRORS.NA_ERROR);
39+catchAndAssertEquals(function() {
40+  WEEKNUM(213123, 1, 1);
41+}, ERRORS.NA_ERROR);
42+catchAndAssertEquals(function() {
43+  WEEKNUM("str");
44+}, ERRORS.VALUE_ERROR);
45+catchAndAssertEquals(function() {
46+  WEEKNUM([]);
47+}, ERRORS.REF_ERROR);
48+catchAndAssertEquals(function() {
49+  WEEKNUM(-10);
50+}, ERRORS.NUM_ERROR);
51+catchAndAssertEquals(function() {
52+  WEEKNUM(10, 4);
53+}, ERRORS.NUM_ERROR);
54+catchAndAssertEquals(function() {
55+  WEEKNUM(10, 22);
56+}, ERRORS.NUM_ERROR);
57 
58 
59