mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: use custom date for summary model to support sqlite deserialization
This commit is contained in:
parent
f7520b2b4a
commit
67a59561c8
@ -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,
|
||||
},
|
||||
|
@ -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"`
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -55,8 +55,8 @@
|
||||
<div class="flex justify-center">
|
||||
<div class="p-1">
|
||||
<div class="flex justify-center p-4 bg-white rounded shadow">
|
||||
<p class="mx-2"><strong>▶️</strong> <span title="Start Time">{{ .FromTime | date }}</span></p>
|
||||
<p class="mx-2"><strong>⏹</strong> <span title="End Time">{{ .ToTime | date }}</span></p>
|
||||
<p class="mx-2"><strong>▶️</strong> <span title="Start Time">{{ .FromTime.T | date }}</span></p>
|
||||
<p class="mx-2"><strong>⏹</strong> <span title="End Time">{{ .ToTime.T | date }}</span></p>
|
||||
<p class="mx-2"><strong>⏱</strong> <span id="total-span" title="Total Hours"></span></p>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user