Skip to content

Commit f190d80

Browse files
committed
fix start/end time tz returned in interval report
1 parent 782da3a commit f190d80

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

coderd/insights.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,10 @@ func (api *API) insightsTemplates(rw http.ResponseWriter, r *http.Request) {
276276
}
277277
for _, row := range dailyUsage {
278278
resp.IntervalReports = append(resp.IntervalReports, codersdk.TemplateInsightsIntervalReport{
279-
StartTime: row.StartTime,
280-
EndTime: row.EndTime,
279+
// NOTE(mafredri): This might not be accurate over DST since the
280+
// parsed location only contains the offset.
281+
StartTime: row.StartTime.In(startTime.Location()),
282+
EndTime: row.EndTime.In(startTime.Location()),
281283
Interval: interval,
282284
TemplateIDs: row.TemplateIDs,
283285
ActiveUsers: row.ActiveUsers,

coderd/testdata/insights/multiple_users_and_workspaces_week_other_timezone_(São_Paulo).json.golden

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,17 @@
7373
},
7474
"interval_reports": [
7575
{
76-
"start_time": "2023-08-15T03:00:00Z",
77-
"end_time": "2023-08-16T03:00:00Z",
76+
"start_time": "2023-08-15T00:00:00-03:00",
77+
"end_time": "2023-08-16T00:00:00-03:00",
7878
"template_ids": [
7979
"00000000-0000-0000-0000-000000000001"
8080
],
8181
"interval": "day",
8282
"active_users": 1
8383
},
8484
{
85-
"start_time": "2023-08-16T03:00:00Z",
86-
"end_time": "2023-08-17T03:00:00Z",
85+
"start_time": "2023-08-16T00:00:00-03:00",
86+
"end_time": "2023-08-17T00:00:00-03:00",
8787
"template_ids": [
8888
"00000000-0000-0000-0000-000000000001",
8989
"00000000-0000-0000-0000-000000000002"
@@ -92,40 +92,40 @@
9292
"active_users": 1
9393
},
9494
{
95-
"start_time": "2023-08-17T03:00:00Z",
96-
"end_time": "2023-08-18T03:00:00Z",
95+
"start_time": "2023-08-17T00:00:00-03:00",
96+
"end_time": "2023-08-18T00:00:00-03:00",
9797
"template_ids": [
9898
"00000000-0000-0000-0000-000000000002"
9999
],
100100
"interval": "day",
101101
"active_users": 1
102102
},
103103
{
104-
"start_time": "2023-08-18T03:00:00Z",
105-
"end_time": "2023-08-19T03:00:00Z",
104+
"start_time": "2023-08-18T00:00:00-03:00",
105+
"end_time": "2023-08-19T00:00:00-03:00",
106106
"template_ids": [],
107107
"interval": "day",
108108
"active_users": 0
109109
},
110110
{
111-
"start_time": "2023-08-19T03:00:00Z",
112-
"end_time": "2023-08-20T03:00:00Z",
111+
"start_time": "2023-08-19T00:00:00-03:00",
112+
"end_time": "2023-08-20T00:00:00-03:00",
113113
"template_ids": [],
114114
"interval": "day",
115115
"active_users": 0
116116
},
117117
{
118-
"start_time": "2023-08-20T03:00:00Z",
119-
"end_time": "2023-08-21T03:00:00Z",
118+
"start_time": "2023-08-20T00:00:00-03:00",
119+
"end_time": "2023-08-21T00:00:00-03:00",
120120
"template_ids": [
121121
"00000000-0000-0000-0000-000000000001"
122122
],
123123
"interval": "day",
124124
"active_users": 1
125125
},
126126
{
127-
"start_time": "2023-08-21T03:00:00Z",
128-
"end_time": "2023-08-22T03:00:00Z",
127+
"start_time": "2023-08-21T00:00:00-03:00",
128+
"end_time": "2023-08-22T00:00:00-03:00",
129129
"template_ids": [],
130130
"interval": "day",
131131
"active_users": 0

0 commit comments

Comments
 (0)