Skip to content

Commit 234f0cb

Browse files
committed
standardize time display
1 parent ab4b266 commit 234f0cb

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

cli/list.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func workspaceListRowFromWorkspace(now time.Time, workspace codersdk.Workspace)
4646
if !ptr.NilOrEmpty(workspace.AutostartSchedule) {
4747
if sched, err := cron.Weekly(*workspace.AutostartSchedule); err == nil {
4848
autostartDisplay = fmt.Sprintf("%s %s (%s)", sched.Time(), sched.DaysOfWeek(), sched.Location())
49-
nextStartDisplay = relative(sched.Next(now).Sub(now))
49+
nextStartDisplay = timeDisplay(sched.Next(now))
5050
}
5151
}
5252

@@ -55,9 +55,8 @@ func workspaceListRowFromWorkspace(now time.Time, workspace codersdk.Workspace)
5555
if !ptr.NilOrZero(workspace.TTLMillis) {
5656
dur := time.Duration(*workspace.TTLMillis) * time.Millisecond
5757
autostopDisplay = durationDisplay(dur)
58-
if !workspace.LatestBuild.Deadline.IsZero() && workspace.LatestBuild.Deadline.Time.After(now) && status == "Running" {
59-
remaining := time.Until(workspace.LatestBuild.Deadline.Time)
60-
nextStopDisplay = fmt.Sprintf("%s (%s)", autostopDisplay, relative(remaining))
58+
if !workspace.LatestBuild.Deadline.IsZero() && workspace.LatestBuild.Transition == codersdk.WorkspaceTransitionStart {
59+
nextStopDisplay = timeDisplay(workspace.LatestBuild.Deadline.Time)
6160
}
6261
}
6362

cli/util.go

+11
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ func durationDisplay(d time.Duration) string {
6262
return sign + durationDisplay
6363
}
6464

65+
// timeDisplay formats a time in the local timezone
66+
// in RFC3339 format.
67+
func timeDisplay(t time.Time) string {
68+
localTz, err := tz.TimezoneIANA()
69+
if err != nil {
70+
localTz = time.UTC
71+
}
72+
73+
return t.In(localTz).Format(time.RFC3339)
74+
}
75+
6576
// relative relativizes a duration with the prefix "ago" or "in"
6677
func relative(d time.Duration) string {
6778
if d > 0 {

0 commit comments

Comments
 (0)