chore: move summary time zone fix into summary model

This commit is contained in:
Ferdinand Mütsch
2025-01-18 00:58:55 +01:00
parent e70edf1fb3
commit b50b208688
4 changed files with 1812 additions and 1808 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -412,6 +412,14 @@ func (s *Summary) WithResolvedAliases(resolve AliasResolver) *Summary {
return s
}
// inplace!
func (s *Summary) InTZ(tz *time.Location) *Summary {
// time zone madness, see https://github.com/muety/wakapi/issues/719#issuecomment-2599365514
s.FromTime = CustomTime(s.FromTime.T().In(tz))
s.ToTime = CustomTime(s.ToTime.T().In(tz))
return s
}
func (s *Summary) findFirstPresentType() (uint8, error) {
for _, t := range s.Types() {
if s.TotalTimeBy(t) != 0 {

View File

@@ -93,11 +93,6 @@ func (s *ActivityService) getChartPastYear(user *models.User, darkTheme, hideAtt
summary.ToTime = models.CustomTime(to)
summary.UserID = user.ID
summary.User = user
} else {
// time zone madness, see https://github.com/muety/wakapi/issues/719#issuecomment-2599365514
// alternatively, we could also just use interval[0] and interval[1] instead
summary.FromTime = models.CustomTime(summary.FromTime.T().In(user.TZ()))
summary.ToTime = models.CustomTime(summary.ToTime.T().In(user.TZ()))
}
mut.Lock()

View File

@@ -96,7 +96,7 @@ func (srv *SummaryService) Aliased(from, to time.Time, user *models.User, f type
}
srv.cache.SetDefault(cacheKey, summary)
return summary.Sorted(), nil
return summary.Sorted().InTZ(user.TZ()), nil
}
func (srv *SummaryService) Retrieve(from, to time.Time, user *models.User, filters *models.Filters) (*models.Summary, error) {
@@ -143,7 +143,7 @@ func (srv *SummaryService) Retrieve(from, to time.Time, user *models.User, filte
summary.KeepOnly(map[uint8]bool{filter.Entity: true}).ApplyFilter(filter)
}
return summary.Sorted(), nil
return summary.Sorted().InTZ(user.TZ()), nil
}
func (srv *SummaryService) Summarize(from, to time.Time, user *models.User, filters *models.Filters) (*models.Summary, error) {
@@ -217,7 +217,7 @@ func (srv *SummaryService) Summarize(from, to time.Time, user *models.User, filt
NumHeartbeats: durations.TotalNumHeartbeats(),
}
return summary.Sorted(), nil
return summary.Sorted().InTZ(user.TZ()), nil
}
// CRUD methods