commit 794f0a92b90ab188fce4a40de03754d3649ae873
parent 6c8dfe04ea11b6cf883fb9dd01dbf5972cb5b90b
Author: Damian Myrda <damian@prime8.dev>
Date: Fri, 23 Oct 2026 05:42:29 +0000
uptime: count days on Pacific clock, not server UTC
Diffstat:
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/internal/config/about.go b/internal/config/about.go
@@ -1,9 +1,24 @@
package config
-import "time"
+import (
+ "time"
+ _ "time/tzdata" // the box may not ship zoneinfo
+)
+
+// HomeZone is the clock the uptime day rolls over on, so the count ticks at
+// local midnight instead of 5pm when the server's UTC date changes.
+var HomeZone = mustZone("America/Los_Angeles")
// Birthday drives the uptime line on the about page.
-var Birthday = time.Date(2008, time.April, 20, 0, 0, 0, 0, time.UTC)
+var Birthday = time.Date(2008, time.April, 20, 0, 0, 0, 0, HomeZone)
+
+func mustZone(name string) *time.Location {
+ loc, err := time.LoadLocation(name)
+ if err != nil {
+ return time.UTC
+ }
+ return loc
+}
type KV struct {
Key, Value string
diff --git a/internal/utils/uptime.go b/internal/utils/uptime.go
@@ -7,6 +7,8 @@ import (
// Uptime renders time since birth in uptime(1) style, e.g. "18y 183d".
func Uptime(birth, now time.Time) string {
+ // count calendar days on the birth date's clock, not the server's
+ now = now.In(birth.Location())
if now.Before(birth) {
return "0d"
}
@@ -16,6 +18,11 @@ func Uptime(birth, now time.Time) string {
years--
anniv = birth.AddDate(years, 0, 0)
}
- days := int(now.Sub(anniv).Hours() / 24)
+ y, m, d := now.Date()
+ today := time.Date(y, m, d, 0, 0, 0, 0, birth.Location())
+ days := 0
+ for anniv.AddDate(0, 0, days+1).Compare(today) <= 0 {
+ days++
+ }
return fmt.Sprintf("%dy %dd", years, days)
}