diff --git a/models/compat/wakatime/v1/summaries.go b/models/compat/wakatime/v1/summaries.go index e064ec7..327bfb8 100644 --- a/models/compat/wakatime/v1/summaries.go +++ b/models/compat/wakatime/v1/summaries.go @@ -64,11 +64,11 @@ func NewSummariesFrom(summaries []*models.Summary, filters *models.Filters) *Sum for i, s := range summaries { data[i] = newDataFrom(s) - if s.FromTime.Before(minDate) { - minDate = s.FromTime + if s.FromTime.T().Before(minDate) { + minDate = s.FromTime.T() } - if s.ToTime.After(maxDate) { - maxDate = s.ToTime + if s.ToTime.T().After(maxDate) { + maxDate = s.ToTime.T() } } @@ -101,8 +101,8 @@ func newDataFrom(s *models.Summary) *summariesData { }, Range: &summariesRange{ Date: time.Now().Format(time.RFC3339), - End: s.ToTime, - Start: s.FromTime, + End: s.ToTime.T(), + Start: s.FromTime.T(), Text: "", Timezone: zone, }, diff --git a/models/summary.go b/models/summary.go index ca33ff6..1141ef0 100644 --- a/models/summary.go +++ b/models/summary.go @@ -36,8 +36,8 @@ const UnknownSummaryKey = "unknown" type Summary struct { ID uint `json:"-" gorm:"primary_key"` UserID string `json:"user_id" gorm:"not null; index:idx_time_summary_user"` - FromTime time.Time `json:"from" gorm:"not null; type:timestamp(3); default:CURRENT_TIMESTAMP(3); index:idx_time_summary_user"` - ToTime time.Time `json:"to" gorm:"not null; type:timestamp(3); default:CURRENT_TIMESTAMP(3); index:idx_time_summary_user"` + FromTime CustomTime `json:"from" gorm:"not null; type:timestamp(3); default:CURRENT_TIMESTAMP(3); index:idx_time_summary_user"` + ToTime CustomTime `json:"to" gorm:"not null; type:timestamp(3); default:CURRENT_TIMESTAMP(3); index:idx_time_summary_user"` Projects []*SummaryItem `json:"projects"` Languages []*SummaryItem `json:"languages"` Editors []*SummaryItem `json:"editors"` diff --git a/services/aggregation.go b/services/aggregation.go index af28edd..abea60d 100644 --- a/services/aggregation.go +++ b/services/aggregation.go @@ -98,7 +98,7 @@ func (srv *AggregationService) trigger(jobs chan<- *AggregationJob) error { userSummaryTimes := make(map[string]time.Time) for _, s := range latestSummaries { - userSummaryTimes[s.UserID] = s.ToTime + userSummaryTimes[s.UserID] = s.ToTime.T() } missingUserIDs := make([]string, 0) diff --git a/services/summary.go b/services/summary.go index e103e40..a061812 100644 --- a/services/summary.go +++ b/services/summary.go @@ -105,8 +105,8 @@ func (srv *SummaryService) Construct(from, to time.Time, user *models.User, reco realFrom, realTo := from, to if len(existingSummaries) > 0 { - realFrom = existingSummaries[0].FromTime - realTo = existingSummaries[len(existingSummaries)-1].ToTime + realFrom = existingSummaries[0].FromTime.T() + realTo = existingSummaries[len(existingSummaries)-1].ToTime.T() for _, summary := range existingSummaries { summary.FillUnknown() @@ -124,8 +124,8 @@ func (srv *SummaryService) Construct(from, to time.Time, user *models.User, reco aggregatedSummary := &models.Summary{ UserID: user.ID, - FromTime: realFrom, - ToTime: realTo, + FromTime: models.CustomTime(realFrom), + ToTime: models.CustomTime(realTo), Projects: projectItems, Languages: languageItems, Editors: editorItems, @@ -256,13 +256,13 @@ func getMissingIntervals(from, to time.Time, existingSummaries []*models.Summary intervals := make([]*Interval, 0) // Pre - if from.Before(existingSummaries[0].FromTime) { - intervals = append(intervals, &Interval{from, existingSummaries[0].FromTime}) + if from.Before(existingSummaries[0].FromTime.T()) { + intervals = append(intervals, &Interval{from, existingSummaries[0].FromTime.T()}) } // Between for i := 0; i < len(existingSummaries)-1; i++ { - t1, t2 := existingSummaries[i].ToTime, existingSummaries[i+1].FromTime + t1, t2 := existingSummaries[i].ToTime.T(), existingSummaries[i+1].FromTime.T() if t1.Equal(t2) { continue } @@ -272,13 +272,13 @@ func getMissingIntervals(from, to time.Time, existingSummaries []*models.Summary 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}) + intervals = append(intervals, &Interval{existingSummaries[i].ToTime.T(), existingSummaries[i+1].FromTime.T()}) } } // Post - if to.After(existingSummaries[len(existingSummaries)-1].ToTime) { - intervals = append(intervals, &Interval{existingSummaries[len(existingSummaries)-1].ToTime, to}) + if to.After(existingSummaries[len(existingSummaries)-1].ToTime.T()) { + intervals = append(intervals, &Interval{existingSummaries[len(existingSummaries)-1].ToTime.T(), to}) } return intervals @@ -306,12 +306,12 @@ func mergeSummaries(summaries []*models.Summary) (*models.Summary, error) { return nil, errors.New("users don't match") } - if s.FromTime.Before(minTime) { - minTime = s.FromTime + if s.FromTime.T().Before(minTime) { + minTime = s.FromTime.T() } - if s.ToTime.After(maxTime) { - maxTime = s.ToTime + if s.ToTime.T().After(maxTime) { + maxTime = s.ToTime.T() } finalSummary.Projects = mergeSummaryItems(finalSummary.Projects, s.Projects) @@ -321,8 +321,8 @@ func mergeSummaries(summaries []*models.Summary) (*models.Summary, error) { finalSummary.Machines = mergeSummaryItems(finalSummary.Machines, s.Machines) } - finalSummary.FromTime = minTime - finalSummary.ToTime = maxTime + finalSummary.FromTime = models.CustomTime(minTime) + finalSummary.ToTime = models.CustomTime(maxTime) return finalSummary, nil } diff --git a/views/summary.tpl.html b/views/summary.tpl.html index cf0c075..359079d 100644 --- a/views/summary.tpl.html +++ b/views/summary.tpl.html @@ -55,8 +55,8 @@
-

▶️ {{ .FromTime | date }}

-

{{ .ToTime | date }}

+

▶️ {{ .FromTime.T | date }}

+

{{ .ToTime.T | date }}