From 11d1d5bc9918c1f85011496b150210f930266ded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferdinand=20M=C3=BCtsch?= Date: Sun, 23 Aug 2020 13:21:23 +0200 Subject: [PATCH] fix: adapt summary generation to new summary bounds --- services/summary.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/services/summary.go b/services/summary.go index 156dea5..4553b6c 100644 --- a/services/summary.go +++ b/services/summary.go @@ -240,7 +240,16 @@ func getMissingIntervals(from, to time.Time, existingSummaries []*models.Summary // Between for i := 0; i < len(existingSummaries)-1; i++ { - if existingSummaries[i].ToTime.Before(existingSummaries[i+1].FromTime) { + t1, t2 := existingSummaries[i].ToTime, existingSummaries[i+1].FromTime + if t1.Equal(t2) { + continue + } + + // round to end of day / start of day, assuming that summaries are always generated on a per-day basis + td1 := time.Date(t1.Year(), t1.Month(), t1.Day()+1, 0, 0, 0, 0, t1.Location()) + td2 := time.Date(t2.Year(), t2.Month(), t2.Day(), 0, 0, 0, 0, t2.Location()) + // one or more day missing in between? + if td1.Before(td2) { intervals = append(intervals, &Interval{existingSummaries[i].ToTime, existingSummaries[i+1].FromTime}) } }