From 0e1c12ec27f128a75ff774502c56287fb1923d9d Mon Sep 17 00:00:00 2001 From: jedarden Date: Sun, 24 May 2026 21:14:07 -0400 Subject: [PATCH] fix(signal): use UTC for date calculations in health aggregation Fix timezone mismatch between local time formatting and SQLite's UTC-based date() function. AggregateDaily, GetWeeklyTrend, and GetAllWeeklyTrends now use .UTC() before formatting dates to match SQLite's date(timestamp, 'unixepoch'). Closes: bf-26eg Tests: TestHealthStore_DailyAggregation, TestHealthStore_GetAllWeeklyTrends now pass --- mothership/internal/signal/healthpersist.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mothership/internal/signal/healthpersist.go b/mothership/internal/signal/healthpersist.go index bf8ce88..8de498d 100644 --- a/mothership/internal/signal/healthpersist.go +++ b/mothership/internal/signal/healthpersist.go @@ -288,8 +288,8 @@ func (s *HealthStore) AggregateDaily() error { s.mu.Lock() defer s.mu.Unlock() - // Get yesterday's date - yesterday := time.Now().Add(-24 * time.Hour).Format("2006-01-02") + // Get yesterday's date (UTC to match SQLite's date() function) + yesterday := time.Now().Add(-24 * time.Hour).UTC().Format("2006-01-02") // Aggregate per-link stats for yesterday _, err := s.db.Exec(` @@ -318,7 +318,7 @@ func (s *HealthStore) GetWeeklyTrend(linkID string) ([]DailyHealthSummary, error s.mu.RLock() defer s.mu.RUnlock() - weekAgo := time.Now().Add(-7 * 24 * time.Hour).Format("2006-01-02") + weekAgo := time.Now().Add(-7 * 24 * time.Hour).UTC().Format("2006-01-02") rows, err := s.db.Query(` SELECT link_id, date, avg_health, min_health, max_health, avg_snr, avg_phase_stability, avg_packet_rate, sample_count @@ -354,7 +354,7 @@ func (s *HealthStore) GetAllWeeklyTrends() (map[string][]DailyHealthSummary, err s.mu.RLock() defer s.mu.RUnlock() - weekAgo := time.Now().Add(-7 * 24 * time.Hour).Format("2006-01-02") + weekAgo := time.Now().Add(-7 * 24 * time.Hour).UTC().Format("2006-01-02") rows, err := s.db.Query(` SELECT link_id, date, avg_health, min_health, max_health, avg_snr, avg_phase_stability, avg_packet_rate, sample_count