Fix minor oscillation in timestamp

Fix a minor oscillation between then date and "now" in timestamp.
This commit is contained in:
Felix Niederwanger 2022-01-05 20:47:11 +01:00
parent ee2720539d
commit 0385389252
Signed by: phoenix
GPG key ID: 6E77A590E3F6D71C

View file

@ -158,7 +158,7 @@ func handlerDevices(w http.ResponseWriter, r *http.Request) {
func timeDeltastr(now int64, tsmp int64) string {
delta := now - tsmp
if delta > 0 {
if delta >= 0 {
if delta < 10 {
// Practically fresh
return "now"
@ -176,12 +176,13 @@ func timeDeltastr(now int64, tsmp int64) string {
return "1 hour ago"
} else if hours < 24 {
return fmt.Sprintf("%d hours ago", hours)
}
days := hours / 24
if days == 1 {
return "yesterday"
} else if days < 7 {
return fmt.Sprintf("%d days ago", days)
} else {
days := hours / 24
if days == 1 {
return "yesterday"
} else if days < 7 {
return fmt.Sprintf("%d days ago", days)
}
}
}
}