@@ -24,6 +24,29 @@ describe('dates', function() {
24
24
nowPlus29 = thisYear + 29 ,
25
25
nowPlus29_2 = nowPlus29 % 100 ;
26
26
27
+ function tweakedTZOffset ( d ) {
28
+ var tzOffset = d . getTimezoneOffset ( ) * 60000 ;
29
+ var offsetTweak = ( d . getUTCMinutes ( ) - d . getMinutes ( ) ) * 60000 +
30
+ ( d . getUTCSeconds ( ) - d . getSeconds ( ) ) * 1000 +
31
+ ( d . getUTCMilliseconds ( ) - d . getMilliseconds ( ) ) ;
32
+
33
+ if ( offsetTweak ) {
34
+ var comb = 3 * 60000 ;
35
+ var tzOffset2 = tzOffset - comb / 2 + Lib . mod ( offsetTweak - tzOffset + comb / 2 , comb ) ;
36
+ // this tweak logic just copies what's in dateTime2ms to account for
37
+ // Chrome's new handling of dates before there were timezones, see
38
+ // https://github.com/plotly/plotly.js/issues/2743
39
+ // This logic has been validated manually using:
40
+ // Plotly.newPlot(gd,[{x:[new Date(1600,0,1),new Date(1600,0,1,0,1)],y:[1,2]}])
41
+ // here just check that it's only happening for years before 1884,
42
+ // and only adjusting the result less than a minute.
43
+ expect ( d . getFullYear ( ) ) . toBeLessThan ( 1884 ) ;
44
+ expect ( Math . abs ( tzOffset2 - tzOffset ) ) . toBeLessThan ( 60000 ) ;
45
+ return tzOffset2 ;
46
+ }
47
+ return tzOffset ;
48
+ }
49
+
27
50
describe ( 'dateTime2ms' , function ( ) {
28
51
it ( 'should accept valid date strings' , function ( ) {
29
52
var tzOffset ;
@@ -62,9 +85,9 @@ describe('dates', function() {
62
85
] . forEach ( function ( v ) {
63
86
// just for sub-millisecond precision tests, use timezoneoffset
64
87
// from the previous date object
65
- if ( v [ 1 ] . getTimezoneOffset ) tzOffset = v [ 1 ] . getTimezoneOffset ( ) ;
88
+ if ( v [ 1 ] . getTimezoneOffset ) tzOffset = tweakedTZOffset ( v [ 1 ] ) ;
66
89
67
- var expected = + v [ 1 ] - ( tzOffset * 60000 ) ;
90
+ var expected = + v [ 1 ] - tzOffset ;
68
91
expect ( Lib . dateTime2ms ( v [ 0 ] ) ) . toBe ( expected , v [ 0 ] ) ;
69
92
70
93
// ISO-8601: all the same stuff with t or T as the separator
@@ -108,7 +131,7 @@ describe('dates', function() {
108
131
d1c ,
109
132
new Date ( 2015 , 8 , 7 , 23 , 34 , 45 , 567 )
110
133
] . forEach ( function ( v ) {
111
- expect ( Lib . dateTime2ms ( v ) ) . toBe ( + v - v . getTimezoneOffset ( ) * 60000 ) ;
134
+ expect ( Lib . dateTime2ms ( v ) ) . toBe ( + v - tweakedTZOffset ( v ) , v . toString ( ) ) ;
112
135
} ) ;
113
136
} ) ;
114
137
0 commit comments