@@ -77,7 +77,7 @@ describe('unit.documents.datatypes.date', () => {
77
77
assertDateOk ( [ new Date ( 200000 , 11 , 1 ) ] , [ 200000 , 12 , 1 ] ) ;
78
78
assertDateOk ( [ new Date ( - 20000 , 0 , 9 ) ] , [ - 20000 , 1 , 9 ] ) ;
79
79
assertDateOk ( [ new Date ( '2000-01-31T12:59:59Z' ) ] , [ 2000 , 1 , 31 ] ) ;
80
- assertDateOk ( [ new Date ( '2000-01-01T00:00:00Z ' ) ] , [ 2000 , 1 , 1 ] ) ;
80
+ assertDateOk ( [ new Date ( '2000-01-01T00:00:00 ' ) ] , [ 2000 , 1 , 1 ] ) ;
81
81
} ) ;
82
82
83
83
it ( 'should create a DataAPIDate from year+month+day' , ( ) => {
@@ -119,11 +119,19 @@ describe('unit.documents.datatypes.date', () => {
119
119
assert . throws ( ( ) => date . ofEpochDay ( 100_000_001 ) , RangeError ) ;
120
120
assert . throws ( ( ) => date . ofEpochDay ( - 100_000_001 ) , RangeError ) ;
121
121
122
- assertDateOk ( date . ofEpochDay ( 0 ) , [ 1970 , 1 , 1 ] ) ;
123
- assertDateOk ( date . ofEpochDay ( 1 ) , [ 1970 , 1 , 2 ] ) ;
124
- assertDateOk ( date . ofEpochDay ( - 1 ) , [ 1969 , 12 , 31 ] ) ;
125
- assertDateOk ( date . ofEpochDay ( 100_000_000 ) , [ 275760 , 9 , 13 ] ) ;
126
- assertDateOk ( date . ofEpochDay ( - 100_000_000 ) , [ - 271821 , 4 , 20 ] ) ;
122
+ const epochDay0 = new Date ( 0 ) ;
123
+ assertDateOk ( date . ofEpochDay ( 0 ) , [ epochDay0 . getFullYear ( ) , epochDay0 . getMonth ( ) + 1 , epochDay0 . getDate ( ) ] ) ;
124
+
125
+ const epochDay1 = new Date ( 86400000 ) ;
126
+ assertDateOk ( date . ofEpochDay ( 1 ) , [ epochDay1 . getFullYear ( ) , epochDay1 . getMonth ( ) + 1 , epochDay1 . getDate ( ) ] ) ;
127
+
128
+ const epochDayMinus1 = new Date ( - 86400000 ) ;
129
+ assertDateOk ( date . ofEpochDay ( - 1 ) , [ epochDayMinus1 . getFullYear ( ) , epochDayMinus1 . getMonth ( ) + 1 , epochDayMinus1 . getDate ( ) ] ) ;
130
+ const epochDay100M = new Date ( 100_000_000 * 86400000 ) ;
131
+ assertDateOk ( date . ofEpochDay ( 100_000_000 ) , [ epochDay100M . getFullYear ( ) , epochDay100M . getMonth ( ) + 1 , epochDay100M . getDate ( ) ] ) ;
132
+
133
+ const epochDayMinus100M = new Date ( - 100_000_000 * 86400000 ) ;
134
+ assertDateOk ( date . ofEpochDay ( - 100_000_000 ) , [ epochDayMinus100M . getFullYear ( ) , epochDayMinus100M . getMonth ( ) + 1 , epochDayMinus100M . getDate ( ) ] ) ;
127
135
} ) ;
128
136
129
137
it ( 'should get date from ofYearDay' , ( ) => {
@@ -135,11 +143,17 @@ describe('unit.documents.datatypes.date', () => {
135
143
assert . throws ( ( ) => date . ofYearDay ( 275760 , 258 ) , RangeError ) ;
136
144
assert . throws ( ( ) => date . ofYearDay ( - 271821 , 109 ) , RangeError ) ;
137
145
138
- assertDateOk ( date . ofYearDay ( 2000 , 1 ) , [ 2000 , 1 , 1 ] ) ;
139
- assertDateOk ( date . ofYearDay ( 2000 , 366 ) , [ 2000 , 12 , 31 ] ) ;
140
- assertDateOk ( date . ofYearDay ( 2004 , 366 ) , [ 2004 , 12 , 31 ] ) ;
141
- assertDateOk ( date . ofYearDay ( 275760 , 257 ) , [ 275760 , 9 , 13 ] ) ;
142
- assertDateOk ( date . ofYearDay ( - 271821 , 110 ) , [ - 271821 , 4 , 20 ] ) ;
146
+ const yearDay2000_1 = new Date ( '2000-01-01' ) ;
147
+ assertDateOk ( date . ofYearDay ( 2000 , 1 ) , [ yearDay2000_1 . getFullYear ( ) , yearDay2000_1 . getMonth ( ) + 1 , yearDay2000_1 . getDate ( ) ] ) ;
148
+
149
+ const yearDay2000_366 = new Date ( '2000-12-31' ) ;
150
+ assertDateOk ( date . ofYearDay ( 2000 , 366 ) , [ yearDay2000_366 . getFullYear ( ) , yearDay2000_366 . getMonth ( ) + 1 , yearDay2000_366 . getDate ( ) ] ) ;
151
+
152
+ const yearDay2004_366 = new Date ( '2004-12-31' ) ;
153
+ assertDateOk ( date . ofYearDay ( 2004 , 366 ) , [ yearDay2004_366 . getFullYear ( ) , yearDay2004_366 . getMonth ( ) + 1 , yearDay2004_366 . getDate ( ) ] ) ;
154
+
155
+ assertDateOk ( date . ofYearDay ( 275760 , 257 ) , [ 275760 , 9 , 12 ] ) ;
156
+ assertDateOk ( date . ofYearDay ( - 271821 , 110 ) , [ - 271821 , 4 , 19 ] ) ;
143
157
} ) ;
144
158
} ) ;
145
159
0 commit comments