1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

Avoid long duration strings: round to nearest second

For example, seeing "Next check: 14m56.245483933s" in feeds list after force-refreshing a feed.

This rounds to the nearest second, so it'll instead be "14m56s"

Other examples from latter two test cases:
- "12.345678s" -> "12s"
- "1m27.654321s" -> "1m28s"
This commit is contained in:
Nick Parker 2023-11-08 18:46:15 +13:00 committed by Frédéric Guillot
parent bc317cfcd1
commit 2bc5ad53c2
2 changed files with 34 additions and 2 deletions

View file

@ -163,17 +163,23 @@ func isEmail(str string) bool {
// Returns the duration in human readable format (hours and minutes).
func duration(t time.Time) string {
return durationImpl(t, time.Now())
}
// Accepts now argument for easy testing
func durationImpl(t time.Time, now time.Time) string {
if t.IsZero() {
return ""
}
diff := time.Until(t)
diff := t.Sub(now)
if diff < 0 {
return ""
}
return diff.String()
// Round to nearest second to get e.g. "14m56s" rather than "14m56.245483933s"
return diff.Round(time.Second).String()
}
func elapsedTime(printer *locale.Printer, tz string, t time.Time) string {