Skip to content

Commit

Permalink
Fix desktop notification duration formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
DingDongSoLong4 committed Dec 12, 2023
1 parent eca5838 commit 7c0b004
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions internal/manager/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,16 @@ func initialisePackageManager(localPath string, srcPathGetter pkg.SourcePathGett
}

func formatDuration(t time.Duration) string {
return fmt.Sprintf("%02.f:%02.f:%02.f", t.Hours(), t.Minutes(), t.Seconds())
switch {
case t >= time.Minute: // 1m23s or 2h45m12s
t = t.Round(time.Second)
case t >= time.Second: // 45.36s
t = t.Round(10 * time.Millisecond)
default: // 51ms
t = t.Round(time.Millisecond)
}

return t.String()
}

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

timeElapsed := j.EndTime.Sub(*j.StartTime)
msg := fmt.Sprintf("Task \"%s\" is finished in %s.", cleanDesc, formatDuration(timeElapsed))
msg := fmt.Sprintf("Task \"%s\" finished in %s.", cleanDesc, formatDuration(timeElapsed))
desktop.SendNotification("Task Finished", msg)
}
case <-ctx.Done():
Expand Down

0 comments on commit 7c0b004

Please sign in to comment.