@@ -25,6 +25,15 @@ test('daysInMonth', () => {
25
25
expect ( HDate . daysInMonth ( KISLEV , 5784 ) ) . toBe ( 29 ) ;
26
26
} ) ;
27
27
28
+ test ( 'daysInMonth-instance' , ( ) => {
29
+ expect ( new HDate ( 3 , IYYAR , 5780 ) . daysInMonth ( ) ) . toBe ( 29 ) ;
30
+ expect ( new HDate ( 3 , SIVAN , 5780 ) . daysInMonth ( ) ) . toBe ( 30 ) ;
31
+ expect ( new HDate ( 3 , CHESHVAN , 5782 ) . daysInMonth ( ) ) . toBe ( 29 ) ;
32
+ expect ( new HDate ( 3 , CHESHVAN , 5783 ) . daysInMonth ( ) ) . toBe ( 30 ) ;
33
+ expect ( new HDate ( 3 , KISLEV , 5783 ) . daysInMonth ( ) ) . toBe ( 30 ) ;
34
+ expect ( new HDate ( 3 , KISLEV , 5784 ) . daysInMonth ( ) ) . toBe ( 29 ) ;
35
+ } ) ;
36
+
28
37
test ( 'ctor-mdy' , ( ) => {
29
38
let d = new HDate ( 29 , CHESHVAN , 5769 ) ;
30
39
let dt = d . greg ( ) ; // 2008-11-27
@@ -115,6 +124,42 @@ test('ctor-copy', () => {
115
124
expect ( d5 . abs ( ) ) . toBe ( d6 . abs ( ) ) ;
116
125
} ) ;
117
126
127
+ test ( 'isLeapYear' , ( ) => {
128
+ expect ( new HDate ( 15 , 'Cheshvan' , 5783 ) . isLeapYear ( ) ) . toBe ( false ) ;
129
+ expect ( new HDate ( 15 , 'Cheshvan' , 5784 ) . isLeapYear ( ) ) . toBe ( true ) ;
130
+ } ) ;
131
+
132
+ test ( 'isLeapYear-static' , ( ) => {
133
+ expect ( HDate . isLeapYear ( 5783 ) ) . toBe ( false ) ;
134
+ expect ( HDate . isLeapYear ( 5784 ) ) . toBe ( true ) ;
135
+ } ) ;
136
+
137
+ test ( 'monthsInYear' , ( ) => {
138
+ expect ( HDate . monthsInYear ( 5783 ) ) . toBe ( 12 ) ;
139
+ expect ( HDate . monthsInYear ( 5784 ) ) . toBe ( 13 ) ;
140
+ } ) ;
141
+
142
+ test ( 'daysInYear' , ( ) => {
143
+ expect ( HDate . daysInYear ( 5783 ) ) . toBe ( 355 ) ;
144
+ expect ( HDate . daysInYear ( 5784 ) ) . toBe ( 383 ) ;
145
+ } ) ;
146
+
147
+ test ( 'longCheshvan' , ( ) => {
148
+ expect ( HDate . longCheshvan ( 5783 ) ) . toBe ( true ) ;
149
+ expect ( HDate . longCheshvan ( 5784 ) ) . toBe ( false ) ;
150
+ } ) ;
151
+
152
+ test ( 'shortKislev' , ( ) => {
153
+ expect ( HDate . shortKislev ( 5783 ) ) . toBe ( false ) ;
154
+ expect ( HDate . shortKislev ( 5784 ) ) . toBe ( true ) ;
155
+ } ) ;
156
+
157
+ test ( 'throws-ctor-1-NaN' , ( ) => {
158
+ expect ( ( ) => {
159
+ new HDate ( NaN ) ;
160
+ } ) . toThrow ( 'HDate called with bad argument: NaN' ) ;
161
+ } ) ;
162
+
118
163
test ( 'throws-ctor-2' , ( ) => {
119
164
expect ( ( ) => {
120
165
new HDate ( 17 , 'Cheshvan' ) ;
@@ -135,6 +180,21 @@ test('throws-ctor-NaN', () => {
135
180
} ) . toThrow ( 'Invalid month number: NaN' ) ;
136
181
} ) ;
137
182
183
+ test ( 'getTishreiMonth' , ( ) => {
184
+ const hd = new HDate ( 15 , 'Cheshvan' , 5769 ) ;
185
+ expect ( hd . getTishreiMonth ( ) ) . toBe ( 2 ) ;
186
+ } ) ;
187
+
188
+ test ( 'hebrew2abs' , ( ) => {
189
+ expect ( HDate . hebrew2abs ( 5769 , CHESHVAN , 15 ) ) . toBe ( 733359 ) ;
190
+ } ) ;
191
+
192
+ test ( 'throws-invalid-units' , ( ) => {
193
+ expect ( ( ) => {
194
+ new HDate ( NaN , 'Sivan' , 5780 ) ;
195
+ } ) . toThrow ( 'HDate called with bad day argument: NaN' ) ;
196
+
197
+ } ) ;
138
198
139
199
test ( 'toString' , ( ) => {
140
200
const d = new HDate ( new Date ( 1751 , 0 , 1 ) ) ;
@@ -153,7 +213,7 @@ test('renderGematriya-suppressNikud', () => {
153
213
} ) ;
154
214
155
215
test ( 'render' , ( ) => {
156
- const hd = new HDate ( 15 , months . CHESHVAN , 5769 ) ;
216
+ const hd = new HDate ( 15 , CHESHVAN , 5769 ) ;
157
217
expect ( hd . render ( '' ) ) . toBe ( '15th of Cheshvan, 5769' ) ;
158
218
expect ( hd . render ( 'en' ) ) . toBe ( '15th of Cheshvan, 5769' ) ;
159
219
expect ( hd . render ( 's' ) ) . toBe ( '15th of Cheshvan, 5769' ) ;
@@ -170,7 +230,7 @@ test('render', () => {
170
230
} ) ;
171
231
172
232
test ( 'render-shvat' , ( ) => {
173
- const hd = new HDate ( 15 , months . SHVAT , 5789 ) ;
233
+ const hd = new HDate ( 15 , SHVAT , 5789 ) ;
174
234
expect ( hd . render ( '' ) ) . toBe ( '15th of Sh’vat, 5789' ) ;
175
235
expect ( hd . render ( 'en' ) ) . toBe ( '15th of Sh’vat, 5789' ) ;
176
236
expect ( hd . render ( 's' ) ) . toBe ( '15th of Sh’vat, 5789' ) ;
@@ -185,7 +245,7 @@ test('render-shvat', () => {
185
245
186
246
187
247
test ( 'render-tevet-ashkenazi' , ( ) => {
188
- const hd = new HDate ( 3 , months . TEVET , 5769 ) ;
248
+ const hd = new HDate ( 3 , TEVET , 5769 ) ;
189
249
expect ( hd . render ( 'en' , false ) ) . toBe ( '3rd of Tevet' ) ;
190
250
expect ( hd . render ( 's' , false ) ) . toBe ( '3rd of Tevet' ) ;
191
251
expect ( hd . render ( 'ashkenazi' , false ) ) . toBe ( '3rd of Teves' ) ;
@@ -226,6 +286,18 @@ test('monthFromName', () => {
226
286
HDate . monthFromName ( sample ) ;
227
287
} ) . toThrow ( `Unable to parse month name: ${ sample } ` ) ;
228
288
}
289
+
290
+ expect ( ( ) => {
291
+ HDate . monthFromName ( 25 ) ;
292
+ } ) . toThrow ( `Invalid month name: 25` ) ;
293
+
294
+ expect ( ( ) => {
295
+ HDate . monthFromName ( - 1 ) ;
296
+ } ) . toThrow ( `Invalid month name: -1` ) ;
297
+
298
+ expect ( ( ) => {
299
+ HDate . monthFromName ( NaN ) ;
300
+ } ) . toThrow ( `Invalid month name: NaN` ) ;
229
301
} ) ;
230
302
231
303
test ( 'getMonthName-throws' , ( ) => {
@@ -336,6 +408,11 @@ test('add', () => {
336
408
expect ( hd . getDate ( ) ) . toBe ( 7 ) ;
337
409
expect ( hd . getFullYear ( ) ) . toBe ( 5769 ) ;
338
410
411
+ hd = cheshvan29 . add ( 1 , 'w' ) ;
412
+ expect ( hd . getMonth ( ) ) . toBe ( KISLEV ) ;
413
+ expect ( hd . getDate ( ) ) . toBe ( 7 ) ;
414
+ expect ( hd . getFullYear ( ) ) . toBe ( 5769 ) ;
415
+
339
416
hd = cheshvan29 . add ( - 3 , 'Days' ) ;
340
417
expect ( hd . getMonth ( ) ) . toBe ( CHESHVAN ) ;
341
418
expect ( hd . getDate ( ) ) . toBe ( 26 ) ;
@@ -427,12 +504,13 @@ test('deltaDays', () => {
427
504
} ) ;
428
505
429
506
test ( 'throws-invalid-units' , ( ) => {
430
-
507
+ const hd = new HDate ( 29 , CHESHVAN , 5769 ) ;
431
508
expect ( ( ) => {
432
-
433
- const hd = new HDate ( 29 , CHESHVAN , 5769 ) ;
434
- hd . add ( 1 , 'foobar' ) ;
435
- } ) . toThrow ( 'Invalid units \'foobar\'' ) ;
509
+ hd . add ( 1 , 'x' ) ;
510
+ } ) . toThrow ( 'Invalid units \'x\'' ) ;
511
+ expect ( ( ) => {
512
+ hd . subtract ( 1 , 'zs' ) ;
513
+ } ) . toThrow ( 'Invalid units \'zs\'' ) ;
436
514
} ) ;
437
515
438
516
test ( 'fromGematriyaString' , ( ) => {
@@ -453,6 +531,12 @@ test('fromGematriyaString whitespace', () => {
453
531
expect ( HDate . fromGematriyaString ( 'ה באדר א תשי"ט ' ) . toString ( ) ) . toBe ( '5 Adar I 5719' ) ;
454
532
} ) ;
455
533
534
+ test ( 'fromGematriyaString-throws' , ( ) => {
535
+ expect ( ( ) => {
536
+ HDate . fromGematriyaString ( 'abc def ghi jkl mno pqr' ) ;
537
+ } ) . toThrow ( 'Unable to parse gematriya string: "abc def ghi jkl mno pqr"' ) ;
538
+ } ) ;
539
+
456
540
test ( 'HDate-rollover-leap' , ( ) => {
457
541
const hd = new HDate ( 30 , IYYAR , 5784 ) ;
458
542
expect ( hd . getFullYear ( ) ) . toBe ( 5784 ) ;
0 commit comments