Skip to content

Commit d5a9865

Browse files
committed
remove mixed tz restrictions, test DST
1 parent 056918e commit d5a9865

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

coderd/insights.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -401,22 +401,6 @@ func parseInsightsStartAndEndTime(ctx context.Context, rw http.ResponseWriter, s
401401
}
402402
*qp.dest = t
403403
}
404-
if startTime.Location().String() != endTime.Location().String() {
405-
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
406-
Message: "Query parameter has invalid value.",
407-
Validations: []codersdk.ValidationError{
408-
{
409-
Field: "start_time",
410-
Detail: fmt.Sprintf("Query param %q must have the same timezone as %q", "start_time", "end_time"),
411-
},
412-
{
413-
Field: "end_time",
414-
Detail: fmt.Sprintf("Query param %q must have the same timezone as %q", "end_time", "start_time"),
415-
},
416-
},
417-
})
418-
return time.Time{}, time.Time{}, false
419-
}
420404
if endTime.Before(startTime) {
421405
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
422406
Message: "Query parameter has invalid value.",

coderd/insights_internal_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,14 @@ func Test_parseInsightsStartAndEndTime(t *testing.T) {
8383
wantOk: true,
8484
},
8585
{
86-
name: "Mixed timezone week",
86+
name: "Daylight savings time",
8787
args: args{
88-
startTime: "2023-07-10T00:00:00Z",
89-
endTime: "2023-07-17T00:00:00+03:00",
88+
startTime: "2023-03-26T00:00:00+02:00",
89+
endTime: "2023-03-27T00:00:00+03:00",
9090
},
91-
wantOk: false,
91+
wantStartTime: time.Date(2023, 3, 26, 0, 0, 0, 0, helsinki),
92+
wantEndTime: time.Date(2023, 3, 27, 0, 0, 0, 0, helsinki),
93+
wantOk: true,
9294
},
9395
{
9496
name: "Bad format",
@@ -133,7 +135,10 @@ func Test_parseInsightsStartAndEndTime(t *testing.T) {
133135

134136
// assert.Equal is unable to test location equality, so we
135137
// use assert.WithinDuration.
136-
assert.Equal(t, tt.wantOk, gotOk)
138+
if !assert.Equal(t, tt.wantOk, gotOk) {
139+
t.Log("Status: ", rw.Result().StatusCode)
140+
t.Log("Body: ", rw.Body.String())
141+
}
137142
assert.WithinDuration(t, tt.wantStartTime, gotStartTime, 0)
138143
assert.True(t, tt.wantStartTime.Equal(gotStartTime))
139144
assert.WithinDuration(t, tt.wantEndTime, gotEndTime, 0)

0 commit comments

Comments
 (0)