Skip to content

Commit 2ef2d89

Browse files
Fix desktop notification duration formatting (#4358)
1 parent 43a9df8 commit 2ef2d89

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

internal/manager/init.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,16 @@ func initialisePackageManager(localPath string, srcPathGetter pkg.SourcePathGett
155155
}
156156

157157
func formatDuration(t time.Duration) string {
158-
return fmt.Sprintf("%02.f:%02.f:%02.f", t.Hours(), t.Minutes(), t.Seconds())
158+
switch {
159+
case t >= time.Minute: // 1m23s or 2h45m12s
160+
t = t.Round(time.Second)
161+
case t >= time.Second: // 45.36s
162+
t = t.Round(10 * time.Millisecond)
163+
default: // 51ms
164+
t = t.Round(time.Millisecond)
165+
}
166+
167+
return t.String()
159168
}
160169

161170
func initJobManager(cfg *config.Config) *job.Manager {
@@ -177,7 +186,7 @@ func initJobManager(cfg *config.Config) *job.Manager {
177186
}
178187

179188
timeElapsed := j.EndTime.Sub(*j.StartTime)
180-
msg := fmt.Sprintf("Task \"%s\" is finished in %s.", cleanDesc, formatDuration(timeElapsed))
189+
msg := fmt.Sprintf("Task \"%s\" finished in %s.", cleanDesc, formatDuration(timeElapsed))
181190
desktop.SendNotification("Task Finished", msg)
182191
}
183192
case <-ctx.Done():

0 commit comments

Comments
 (0)