fix off by one error in activity log nil padding for month data (#15731)
This commit is contained in:
parent
a49f1b9e6b
commit
a5f70d7fe0
|
@ -1736,6 +1736,9 @@ func modifyResponseMonths(months []*ResponseMonth, start time.Time, end time.Tim
|
||||||
return months
|
return months
|
||||||
}
|
}
|
||||||
start = timeutil.StartOfMonth(start)
|
start = timeutil.StartOfMonth(start)
|
||||||
|
if timeutil.IsCurrentMonth(end, time.Now().UTC()) {
|
||||||
|
end = timeutil.StartOfMonth(end).AddDate(0, -1, 0)
|
||||||
|
}
|
||||||
end = timeutil.EndOfMonth(end)
|
end = timeutil.EndOfMonth(end)
|
||||||
modifiedResponseMonths := make([]*ResponseMonth, 0)
|
modifiedResponseMonths := make([]*ResponseMonth, 0)
|
||||||
firstMonth, err := time.Parse(time.RFC3339, months[0].Timestamp)
|
firstMonth, err := time.Parse(time.RFC3339, months[0].Timestamp)
|
||||||
|
@ -1753,6 +1756,10 @@ func modifyResponseMonths(months []*ResponseMonth, start time.Time, end time.Tim
|
||||||
lastMonth = timeutil.StartOfMonth(lastMonth.AddDate(0, 1, 0))
|
lastMonth = timeutil.StartOfMonth(lastMonth.AddDate(0, 1, 0))
|
||||||
monthPlaceholder := &ResponseMonth{Timestamp: lastMonth.UTC().Format(time.RFC3339)}
|
monthPlaceholder := &ResponseMonth{Timestamp: lastMonth.UTC().Format(time.RFC3339)}
|
||||||
modifiedResponseMonths = append(modifiedResponseMonths, monthPlaceholder)
|
modifiedResponseMonths = append(modifiedResponseMonths, monthPlaceholder)
|
||||||
|
|
||||||
|
// reset lastMonth to be the end of the month so we can make an apt comparison
|
||||||
|
// in the next loop iteration
|
||||||
|
lastMonth = timeutil.EndOfMonth(lastMonth)
|
||||||
}
|
}
|
||||||
return modifiedResponseMonths
|
return modifiedResponseMonths
|
||||||
}
|
}
|
||||||
|
|
|
@ -472,6 +472,36 @@ func TestActivityLog_SaveEntitiesToStorage(t *testing.T) {
|
||||||
expectedEntityIDs(t, out, ids)
|
expectedEntityIDs(t, out, ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestModifyResponseMonthsNilAppend(t *testing.T) {
|
||||||
|
end := time.Now().UTC()
|
||||||
|
start := timeutil.StartOfMonth(end).AddDate(0, -5, 0)
|
||||||
|
responseMonthTimestamp := timeutil.StartOfMonth(end).AddDate(0, -3, 0).Format(time.RFC3339)
|
||||||
|
responseMonths := []*ResponseMonth{{Timestamp: responseMonthTimestamp}}
|
||||||
|
months := modifyResponseMonths(responseMonths, start, end)
|
||||||
|
if len(months) != 5 {
|
||||||
|
t.Fatal("wrong number of months padded")
|
||||||
|
}
|
||||||
|
for _, m := range months {
|
||||||
|
ts, err := time.Parse(time.RFC3339, m.Timestamp)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !ts.Equal(start) {
|
||||||
|
t.Fatalf("incorrect time in month sequence timestamps: expected %+v, got %+v", start, ts)
|
||||||
|
}
|
||||||
|
start = timeutil.StartOfMonth(start).AddDate(0, 1, 0)
|
||||||
|
}
|
||||||
|
// The following is a redundant check, but for posterity and readability I've
|
||||||
|
// made it explicit.
|
||||||
|
lastMonth, err := time.Parse(time.RFC3339, months[4].Timestamp)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if timeutil.IsCurrentMonth(lastMonth, time.Now().UTC()) {
|
||||||
|
t.Fatalf("do not include current month timestamp in nil padding for months")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestActivityLog_ReceivedFragment(t *testing.T) {
|
func TestActivityLog_ReceivedFragment(t *testing.T) {
|
||||||
core, _, _ := TestCoreUnsealed(t)
|
core, _, _ := TestCoreUnsealed(t)
|
||||||
a := core.activityLog
|
a := core.activityLog
|
||||||
|
|
Loading…
Reference in New Issue