@@ -86,28 +86,6 @@ func list() *cobra.Command {
86
86
}
87
87
88
88
duration := time .Now ().UTC ().Sub (workspace .LatestBuild .Job .CreatedAt ).Truncate (time .Second )
89
- if duration > time .Hour {
90
- duration = duration .Truncate (time .Hour )
91
- }
92
- if duration > time .Minute {
93
- duration = duration .Truncate (time .Minute )
94
- }
95
- days := 0
96
- for duration .Hours () > 24 {
97
- days ++
98
- duration -= 24 * time .Hour
99
- }
100
- durationDisplay := duration .String ()
101
- if days > 0 {
102
- durationDisplay = fmt .Sprintf ("%dd%s" , days , durationDisplay )
103
- }
104
- if strings .HasSuffix (durationDisplay , "m0s" ) {
105
- durationDisplay = durationDisplay [:len (durationDisplay )- 2 ]
106
- }
107
- if strings .HasSuffix (durationDisplay , "h0m" ) {
108
- durationDisplay = durationDisplay [:len (durationDisplay )- 2 ]
109
- }
110
-
111
89
autostartDisplay := "-"
112
90
if workspace .AutostartSchedule != "" {
113
91
if sched , err := schedule .Weekly (workspace .AutostartSchedule ); err == nil {
@@ -117,15 +95,18 @@ func list() *cobra.Command {
117
95
118
96
autostopDisplay := "-"
119
97
if workspace .TTL != nil {
120
- autostopDisplay = workspace .TTL .String ()
98
+ autostopDisplay = durationDisplay (* workspace .TTL )
99
+ if has , ext := hasExtension (workspace ); has {
100
+ autostopDisplay += fmt .Sprintf (" (+%s)" , durationDisplay (ext ))
101
+ }
121
102
}
122
103
123
104
user := usersByID [workspace .OwnerID ]
124
105
tableWriter .AppendRow (table.Row {
125
106
user .Username + "/" + workspace .Name ,
126
107
workspace .TemplateName ,
127
108
status ,
128
- durationDisplay ,
109
+ durationDisplay ( duration ) ,
129
110
workspace .Outdated ,
130
111
autostartDisplay ,
131
112
autostopDisplay ,
@@ -139,3 +120,47 @@ func list() *cobra.Command {
139
120
"Specify a column to filter in the table." )
140
121
return cmd
141
122
}
123
+
124
+ func hasExtension (ws codersdk.Workspace ) (bool , time.Duration ) {
125
+ if ws .LatestBuild .Transition != codersdk .WorkspaceTransitionStart {
126
+ return false , 0
127
+ }
128
+ if ws .LatestBuild .Deadline .IsZero () {
129
+ return false , 0
130
+ }
131
+ if ws .TTL == nil {
132
+ return false , 0
133
+ }
134
+ delta := ws .LatestBuild .Deadline .Add (- * ws .TTL ).Sub (ws .LatestBuild .UpdatedAt ).Round (time .Minute )
135
+ if delta <= 0 {
136
+ return false , 0
137
+ }
138
+
139
+ return true , delta
140
+ }
141
+
142
+ func durationDisplay (d time.Duration ) string {
143
+ duration := d
144
+ if duration > time .Hour {
145
+ duration = duration .Truncate (time .Hour )
146
+ }
147
+ if duration > time .Minute {
148
+ duration = duration .Truncate (time .Minute )
149
+ }
150
+ days := 0
151
+ for duration .Hours () > 24 {
152
+ days ++
153
+ duration -= 24 * time .Hour
154
+ }
155
+ durationDisplay := duration .String ()
156
+ if days > 0 {
157
+ durationDisplay = fmt .Sprintf ("%dd%s" , days , durationDisplay )
158
+ }
159
+ if strings .HasSuffix (durationDisplay , "m0s" ) {
160
+ durationDisplay = durationDisplay [:len (durationDisplay )- 2 ]
161
+ }
162
+ if strings .HasSuffix (durationDisplay , "h0m" ) {
163
+ durationDisplay = durationDisplay [:len (durationDisplay )- 2 ]
164
+ }
165
+ return durationDisplay
166
+ }
0 commit comments