spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
[WIP:WEEKNUM] more tests for types 13 through 21
author
Ben Vogt <[email protected]>
date
2017-04-15 03:19:13
stats
2 file(s) changed, 247 insertions(+), 2 deletions(-)
files
src/RawFormulas/Date.ts
tests/DateFormulasTest.ts
  1diff --git a/src/RawFormulas/Date.ts b/src/RawFormulas/Date.ts
  2index c01d51a..1550bae 100644
  3--- a/src/RawFormulas/Date.ts
  4+++ b/src/RawFormulas/Date.ts
  5@@ -335,11 +335,26 @@ var WEEKNUM = function (...values) {
  6     }
  7     return weeksCount;
  8   } else if (shiftType === 16) {
  9-
 10+    var SHIFTER = [1, 2, 3, 4, 5, 6, 0];
 11+    var startOfYear = moment.utc(dm).startOf("year");
 12+    var weeksCount = 1;
 13+    var d = moment.utc(dm).startOf("year").add(6 - SHIFTER[startOfYear.day()], "days");
 14+    while (d.isBefore(dm)) {
 15+      d.add(7, "days");
 16+      weeksCount++;
 17+    }
 18+    return weeksCount;
 19   } else if (shiftType === 17) {
 20-
 21+    var startOfYear = moment.utc(dm).startOf("year");
 22+    var weeksCount = 1;
 23+    var d = moment.utc(dm).startOf("year").add(6 - startOfYear.day(), "days");
 24+    while (d.isBefore(dm)) {
 25+      d.add(7, "days");
 26+      weeksCount++;
 27+    }
 28+    return weeksCount;
 29   } else if (shiftType === 21) {
 30-
 31+    return dm.isoWeek();
 32   } else {
 33     throw new NumError("Function WEEKNUM parameter 2 value " + shiftType + " is out of range.");
 34   }
 35diff --git a/tests/DateFormulasTest.ts b/tests/DateFormulasTest.ts
 36index d6659ab..143eafb 100644
 37--- a/tests/DateFormulasTest.ts
 38+++ b/tests/DateFormulasTest.ts
 39@@ -250,7 +250,6 @@ assertEquals(WEEKNUM(743, 14), 3);
 40 assertEquals(WEEKNUM(744, 14), 3);
 41 assertEquals(WEEKNUM(745, 14), 3);
 42 assertEquals(WEEKNUM(746, 14), 3);
 43-
 44 //type=15
 45 assertEquals(WEEKNUM(23734, 15), 52);
 46 assertEquals(WEEKNUM(23735, 15), 52);
 47@@ -325,7 +324,235 @@ assertEquals(WEEKNUM(743, 15), 3);
 48 assertEquals(WEEKNUM(744, 15), 3);
 49 assertEquals(WEEKNUM(745, 15), 3);
 50 assertEquals(WEEKNUM(746, 15), 3);
 51+//type=16
 52+assertEquals(WEEKNUM(23734, 16), 52);
 53+assertEquals(WEEKNUM(23735, 16), 52);
 54+assertEquals(WEEKNUM(23736, 16), 52);
 55+assertEquals(WEEKNUM(23737, 16), 53);
 56+assertEquals(WEEKNUM(23738, 16), 53);
 57+assertEquals(WEEKNUM(23739, 16), 53);
 58+assertEquals(WEEKNUM(23740, 16), 53);
 59+assertEquals(WEEKNUM(23741, 16), 53);
 60+assertEquals(WEEKNUM(23742, 16), 53);
 61+assertEquals(WEEKNUM(23743, 16), 1);
 62+assertEquals(WEEKNUM(23744, 16), 2);
 63+assertEquals(WEEKNUM(23745, 16), 2);
 64+assertEquals(WEEKNUM(23746, 16), 2);
 65+assertEquals(WEEKNUM(23747, 16), 2);
 66+assertEquals(WEEKNUM(23748, 16), 2);
 67+assertEquals(WEEKNUM(23749, 16), 2);
 68+assertEquals(WEEKNUM(23750, 16), 2);
 69+assertEquals(WEEKNUM(23751, 16), 3);
 70+assertEquals(WEEKNUM(23752, 16), 3);
 71+assertEquals(WEEKNUM(23753, 16), 3);
 72+assertEquals(WEEKNUM(23754, 16), 3);
 73+assertEquals(WEEKNUM(23755, 16), 3);
 74+assertEquals(WEEKNUM(23756, 16), 3);
 75+assertEquals(WEEKNUM(23757, 16), 3);
 76+assertEquals(WEEKNUM(23758, 16), 4);
 77+assertEquals(WEEKNUM(23759, 16), 4);
 78+assertEquals(WEEKNUM(23760, 16), 4);
 79+// //type=16 again
 80+assertEquals(WEEKNUM(355, 16), 51);
 81+assertEquals(WEEKNUM(356, 16), 51);
 82+assertEquals(WEEKNUM(357, 16), 52);
 83+assertEquals(WEEKNUM(358, 16), 52);
 84+assertEquals(WEEKNUM(359, 16), 52);
 85+assertEquals(WEEKNUM(360, 16), 52);
 86+assertEquals(WEEKNUM(361, 16), 52);
 87+assertEquals(WEEKNUM(362, 16), 52);
 88+assertEquals(WEEKNUM(363, 16), 52);
 89+assertEquals(WEEKNUM(364, 16), 53);
 90+assertEquals(WEEKNUM(365, 16), 53);
 91+assertEquals(WEEKNUM(366, 16), 53);
 92+assertEquals(WEEKNUM(367, 16), 1);
 93+assertEquals(WEEKNUM(368, 16), 1);
 94+assertEquals(WEEKNUM(369, 16), 1);
 95+assertEquals(WEEKNUM(370, 16), 1);
 96+assertEquals(WEEKNUM(371, 16), 2);
 97+assertEquals(WEEKNUM(372, 16), 2);
 98+assertEquals(WEEKNUM(373, 16), 2);
 99+assertEquals(WEEKNUM(374, 16), 2);
100+assertEquals(WEEKNUM(375, 16), 2);
101+assertEquals(WEEKNUM(376, 16), 2);
102+assertEquals(WEEKNUM(377, 16), 2);
103+assertEquals(WEEKNUM(378, 16), 3);
104+assertEquals(WEEKNUM(379, 16), 3);
105+assertEquals(WEEKNUM(380, 16), 3);
106+assertEquals(WEEKNUM(381, 16), 3);
107+//type=16 again
108+assertEquals(WEEKNUM(730, 16), 53);
109+assertEquals(WEEKNUM(731, 16), 53);
110+assertEquals(WEEKNUM(732, 16), 1);
111+assertEquals(WEEKNUM(733, 16), 1);
112+assertEquals(WEEKNUM(734, 16), 1);
113+assertEquals(WEEKNUM(735, 16), 2);
114+assertEquals(WEEKNUM(736, 16), 2);
115+assertEquals(WEEKNUM(737, 16), 2);
116+assertEquals(WEEKNUM(738, 16), 2);
117+assertEquals(WEEKNUM(739, 16), 2);
118+assertEquals(WEEKNUM(740, 16), 2);
119+assertEquals(WEEKNUM(741, 16), 2);
120+assertEquals(WEEKNUM(742, 16), 3);
121+assertEquals(WEEKNUM(743, 16), 3);
122+assertEquals(WEEKNUM(744, 16), 3);
123+assertEquals(WEEKNUM(745, 16), 3);
124+assertEquals(WEEKNUM(746, 16), 3);
125+//type=17
126+assertEquals(WEEKNUM(23734, 17), 52);
127+assertEquals(WEEKNUM(23735, 17), 52);
128+assertEquals(WEEKNUM(23736, 17), 52);
129+assertEquals(WEEKNUM(23737, 17), 52);
130+assertEquals(WEEKNUM(23738, 17), 53);
131+assertEquals(WEEKNUM(23739, 17), 53);
132+assertEquals(WEEKNUM(23740, 17), 53);
133+assertEquals(WEEKNUM(23741, 17), 53);
134+assertEquals(WEEKNUM(23742, 17), 53);
135+assertEquals(WEEKNUM(23743, 17), 1);
136+assertEquals(WEEKNUM(23744, 17), 1);
137+assertEquals(WEEKNUM(23745, 17), 2);
138+assertEquals(WEEKNUM(23746, 17), 2);
139+assertEquals(WEEKNUM(23747, 17), 2);
140+assertEquals(WEEKNUM(23748, 17), 2);
141+assertEquals(WEEKNUM(23749, 17), 2);
142+assertEquals(WEEKNUM(23750, 17), 2);
143+assertEquals(WEEKNUM(23751, 17), 2);
144+assertEquals(WEEKNUM(23752, 17), 3);
145+assertEquals(WEEKNUM(23753, 17), 3);
146+assertEquals(WEEKNUM(23754, 17), 3);
147+assertEquals(WEEKNUM(23755, 17), 3);
148+assertEquals(WEEKNUM(23756, 17), 3);
149+assertEquals(WEEKNUM(23757, 17), 3);
150+assertEquals(WEEKNUM(23758, 17), 3);
151+assertEquals(WEEKNUM(23759, 17), 4);
152+assertEquals(WEEKNUM(23760, 17), 4);
153+// //type=17 again
154+assertEquals(WEEKNUM(355, 17), 51);
155+assertEquals(WEEKNUM(356, 17), 51);
156+assertEquals(WEEKNUM(357, 17), 51);
157+assertEquals(WEEKNUM(358, 17), 52);
158+assertEquals(WEEKNUM(359, 17), 52);
159+assertEquals(WEEKNUM(360, 17), 52);
160+assertEquals(WEEKNUM(361, 17), 52);
161+assertEquals(WEEKNUM(362, 17), 52);
162+assertEquals(WEEKNUM(363, 17), 52);
163+assertEquals(WEEKNUM(364, 17), 52);
164+assertEquals(WEEKNUM(365, 17), 53);
165+assertEquals(WEEKNUM(366, 17), 53);
166+assertEquals(WEEKNUM(367, 17), 1);
167+assertEquals(WEEKNUM(368, 17), 1);
168+assertEquals(WEEKNUM(369, 17), 1);
169+assertEquals(WEEKNUM(370, 17), 1);
170+assertEquals(WEEKNUM(371, 17), 1);
171+assertEquals(WEEKNUM(372, 17), 2);
172+assertEquals(WEEKNUM(373, 17), 2);
173+assertEquals(WEEKNUM(374, 17), 2);
174+assertEquals(WEEKNUM(375, 17), 2);
175+assertEquals(WEEKNUM(376, 17), 2);
176+assertEquals(WEEKNUM(377, 17), 2);
177+assertEquals(WEEKNUM(378, 17), 2);
178+assertEquals(WEEKNUM(379, 17), 3);
179+assertEquals(WEEKNUM(380, 17), 3);
180+assertEquals(WEEKNUM(381, 17), 3);
181+//type=17 again
182+assertEquals(WEEKNUM(730, 17), 53);
183+assertEquals(WEEKNUM(731, 17), 53);
184+assertEquals(WEEKNUM(732, 17), 1);
185+assertEquals(WEEKNUM(733, 17), 1);
186+assertEquals(WEEKNUM(734, 17), 1);
187+assertEquals(WEEKNUM(735, 17), 1);
188+assertEquals(WEEKNUM(736, 17), 2);
189+assertEquals(WEEKNUM(737, 17), 2);
190+assertEquals(WEEKNUM(738, 17), 2);
191+assertEquals(WEEKNUM(739, 17), 2);
192+assertEquals(WEEKNUM(740, 17), 2);
193+assertEquals(WEEKNUM(741, 17), 2);
194+assertEquals(WEEKNUM(742, 17), 2);
195+assertEquals(WEEKNUM(743, 17), 3);
196+assertEquals(WEEKNUM(744, 17), 3);
197+assertEquals(WEEKNUM(745, 17), 3);
198+assertEquals(WEEKNUM(746, 17), 3);
199 
200+//type=21
201+assertEquals(WEEKNUM(23730, 21), 51);
202+assertEquals(WEEKNUM(23731, 21), 51);
203+assertEquals(WEEKNUM(23732, 21), 52);
204+assertEquals(WEEKNUM(23733, 21), 52);
205+assertEquals(WEEKNUM(23734, 21), 52);
206+assertEquals(WEEKNUM(23735, 21), 52);
207+assertEquals(WEEKNUM(23736, 21), 52);
208+assertEquals(WEEKNUM(23737, 21), 52);
209+assertEquals(WEEKNUM(23738, 21), 52);
210+assertEquals(WEEKNUM(23739, 21), 53);
211+assertEquals(WEEKNUM(23740, 21), 53);
212+assertEquals(WEEKNUM(23741, 21), 53);
213+assertEquals(WEEKNUM(23742, 21), 53);
214+assertEquals(WEEKNUM(23743, 21), 53);
215+assertEquals(WEEKNUM(23744, 21), 53);
216+assertEquals(WEEKNUM(23745, 21), 53);
217+assertEquals(WEEKNUM(23746, 21), 1);
218+assertEquals(WEEKNUM(23747, 21), 1);
219+assertEquals(WEEKNUM(23748, 21), 1);
220+assertEquals(WEEKNUM(23749, 21), 1);
221+assertEquals(WEEKNUM(23750, 21), 1);
222+assertEquals(WEEKNUM(23751, 21), 1);
223+assertEquals(WEEKNUM(23752, 21), 1);
224+assertEquals(WEEKNUM(23753, 21), 2);
225+assertEquals(WEEKNUM(23754, 21), 2);
226+assertEquals(WEEKNUM(23755, 21), 2);
227+assertEquals(WEEKNUM(23756, 21), 2);
228+assertEquals(WEEKNUM(23757, 21), 2);
229+assertEquals(WEEKNUM(23758, 21), 2);
230+assertEquals(WEEKNUM(23759, 21), 2);
231+assertEquals(WEEKNUM(23760, 21), 3);
232+// //type=21 again
233+assertEquals(WEEKNUM(355, 21), 51);
234+assertEquals(WEEKNUM(356, 21), 51);
235+assertEquals(WEEKNUM(357, 21), 51);
236+assertEquals(WEEKNUM(358, 21), 51);
237+assertEquals(WEEKNUM(359, 21), 52);
238+assertEquals(WEEKNUM(360, 21), 52);
239+assertEquals(WEEKNUM(361, 21), 52);
240+assertEquals(WEEKNUM(362, 21), 52);
241+assertEquals(WEEKNUM(363, 21), 52);
242+assertEquals(WEEKNUM(364, 21), 52);
243+assertEquals(WEEKNUM(365, 21), 52);
244+assertEquals(WEEKNUM(366, 21), 1);
245+assertEquals(WEEKNUM(367, 21), 1);
246+assertEquals(WEEKNUM(368, 21), 1);
247+assertEquals(WEEKNUM(369, 21), 1);
248+assertEquals(WEEKNUM(370, 21), 1);
249+assertEquals(WEEKNUM(371, 21), 1);
250+assertEquals(WEEKNUM(372, 21), 1);
251+assertEquals(WEEKNUM(373, 21), 2);
252+assertEquals(WEEKNUM(374, 21), 2);
253+assertEquals(WEEKNUM(375, 21), 2);
254+assertEquals(WEEKNUM(376, 21), 2);
255+assertEquals(WEEKNUM(377, 21), 2);
256+assertEquals(WEEKNUM(378, 21), 2);
257+assertEquals(WEEKNUM(379, 21), 2);
258+assertEquals(WEEKNUM(380, 21), 3);
259+assertEquals(WEEKNUM(381, 21), 3);
260+// //type=21 again
261+assertEquals(WEEKNUM(728, 21), 52);
262+assertEquals(WEEKNUM(729, 21), 52);
263+assertEquals(WEEKNUM(730, 21), 1);
264+assertEquals(WEEKNUM(731, 21), 1);
265+assertEquals(WEEKNUM(732, 21), 1);
266+assertEquals(WEEKNUM(733, 21), 1);
267+assertEquals(WEEKNUM(734, 21), 1);
268+assertEquals(WEEKNUM(735, 21), 1);
269+assertEquals(WEEKNUM(736, 21), 1);
270+assertEquals(WEEKNUM(737, 21), 2);
271+assertEquals(WEEKNUM(738, 21), 2);
272+assertEquals(WEEKNUM(739, 21), 2);
273+assertEquals(WEEKNUM(740, 21), 2);
274+assertEquals(WEEKNUM(741, 21), 2);
275+assertEquals(WEEKNUM(742, 21), 2);
276+assertEquals(WEEKNUM(743, 21), 2);
277+assertEquals(WEEKNUM(744, 21), 3);
278+assertEquals(WEEKNUM(745, 21), 3);
279+assertEquals(WEEKNUM(746, 21), 3);
280 
281 
282