File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -140,14 +140,14 @@ let getExcelRowCol = (str) => {
140140let getExcelTS = ( date ) => {
141141
142142 let thisDt = new Date ( date ) ;
143- thisDt . setDate ( thisDt . getDate ( ) + 1 ) ;
143+ thisDt = new Date ( thisDt . getTime ( ) + 24 * 60 * 60 * 1000 ) ;
144144
145145 let epoch = new Date ( '1900-01-01T00:00:00.0000Z' ) ;
146146
147147 // Handle legacy leap year offset as described in §18.17.4.1
148148 const legacyLeapDate = new Date ( '1900-02-28T23:59:59.999Z' ) ;
149149 if ( thisDt - legacyLeapDate > 0 ) {
150- thisDt . setDate ( thisDt . getDate ( ) + 1 ) ;
150+ thisDt = new Date ( thisDt . getTime ( ) + 24 * 60 * 60 * 1000 ) ;
151151 }
152152
153153 // Get milliseconds between date sent to function and epoch
Original file line number Diff line number Diff line change @@ -31,6 +31,12 @@ test('Test library functions', (t) => {
3131 t . equals ( xl . getExcelTS ( new Date ( '1900-01-01T12:00:00Z' ) ) , 1.5000000 , 'Correctly translated date 1900-01-01T12:00:00Z' ) ;
3232 t . equals ( xl . getExcelTS ( new Date ( '9999-12-31T23:59:59Z' ) ) , 2958465.9999884 , 'Correctly translated date 9999-12-31T23:59:59Z' ) ;
3333
34+ /**
35+ * getExcelTS should handle dates within 2 days of daylight savings change (2020-03-08 for example)
36+ */
37+ t . equals ( xl . getExcelTS ( new Date ( '2020-03-05T15:38:00Z' ) ) , 43895.6513889 , 'Correctly translated date 2020-03-01T15:38:00Z' ) ;
38+ t . equals ( xl . getExcelTS ( new Date ( '2020-03-06T15:38:00Z' ) ) , 43896.6513889 , 'Correctly translated date 2020-03-06T15:38:00Z' ) ;
39+
3440 /**
3541 * Tests as defined in §18.17.4.1 of ECMA-376, Second Edition, Part 1 - Fundamentals And Markup Language Reference
3642 * The serial value 2.0000000... represents 1900-01-01
You can’t perform that action at this time.
0 commit comments