@@ -205,6 +205,7 @@ func TestTimezoneOffsets(t *testing.T) {
205
205
206
206
testCases := []struct {
207
207
Name string
208
+ Now time.Time
208
209
Loc * time.Location
209
210
ExpectedOffset int
210
211
}{
@@ -213,29 +214,52 @@ func TestTimezoneOffsets(t *testing.T) {
213
214
Loc : time .UTC ,
214
215
ExpectedOffset : 0 ,
215
216
},
216
- // The following test cases are broken re: daylight savings
217
- //{
218
- // Name: "Eastern",
219
- // Loc: must(time.LoadLocation("America/New_York")),
220
- // ExpectedOffset: -4,
221
- // },
222
- //{
223
- // Name: "Central",
224
- // Loc: must(time.LoadLocation("America/Chicago")),
225
- // ExpectedOffset: -5,
226
- // },
227
- //{
228
- // Name: "Ireland",
229
- // Loc: must(time.LoadLocation("Europe/Dublin")),
230
- // ExpectedOffset: 1,
231
- // },
217
+
218
+ {
219
+ Name : "Eastern" ,
220
+ Now : time .Date (2021 , 2 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
221
+ Loc : must (time .LoadLocation ("America/New_York" )),
222
+ ExpectedOffset : 5 ,
223
+ },
224
+ {
225
+ // Daylight savings is on the 14th of March to Nov 7 in 2021
226
+ Name : "EasternDaylightSavings" ,
227
+ Now : time .Date (2021 , 3 , 16 , 0 , 0 , 0 , 0 , time .UTC ),
228
+ Loc : must (time .LoadLocation ("America/New_York" )),
229
+ ExpectedOffset : 4 ,
230
+ },
231
+ {
232
+ Name : "Central" ,
233
+ Now : time .Date (2021 , 2 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
234
+ Loc : must (time .LoadLocation ("America/Chicago" )),
235
+ ExpectedOffset : 6 ,
236
+ },
237
+ {
238
+ Name : "CentralDaylightSavings" ,
239
+ Now : time .Date (2021 , 3 , 16 , 0 , 0 , 0 , 0 , time .UTC ),
240
+ Loc : must (time .LoadLocation ("America/Chicago" )),
241
+ ExpectedOffset : 5 ,
242
+ },
243
+ {
244
+ Name : "Ireland" ,
245
+ Now : time .Date (2021 , 2 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
246
+ Loc : must (time .LoadLocation ("Europe/Dublin" )),
247
+ ExpectedOffset : 0 ,
248
+ },
249
+ {
250
+ Name : "IrelandDaylightSavings" ,
251
+ Now : time .Date (2021 , 4 , 3 , 0 , 0 , 0 , 0 , time .UTC ),
252
+ Loc : must (time .LoadLocation ("Europe/Dublin" )),
253
+ ExpectedOffset : - 1 ,
254
+ },
232
255
{
233
256
Name : "HalfHourTz" ,
257
+ Now : time .Date (2024 , 1 , 20 , 6 , 0 , 0 , 0 , must (time .LoadLocation ("Asia/Yangon" ))),
234
258
// This timezone is +6:30, but the function rounds to the nearest hour.
235
259
// This is intentional because our DAUs endpoint only covers 1-hour offsets.
236
260
// If the user is in a non-hour timezone, they get the closest hour bucket.
237
261
Loc : must (time .LoadLocation ("Asia/Yangon" )),
238
- ExpectedOffset : 6 ,
262
+ ExpectedOffset : - 6 ,
239
263
},
240
264
}
241
265
@@ -244,7 +268,7 @@ func TestTimezoneOffsets(t *testing.T) {
244
268
t .Run (c .Name , func (t * testing.T ) {
245
269
t .Parallel ()
246
270
247
- offset := codersdk .TimezoneOffsetHour ( c .Loc )
271
+ offset := codersdk .TimezoneOffsetHourWithTime ( c . Now , c .Loc )
248
272
require .Equal (t , c .ExpectedOffset , offset )
249
273
})
250
274
}
0 commit comments