Skip to content

Commit

Permalink
refactor some code in modifyResponseMonths and ensure that the last m…
Browse files Browse the repository at this point in the history
…o… (#15767)

* refactr some code in modifyResponseMonths and ensure that the last month comparison with end is comparing end of month with end of month

* calibrate end of month apropriately and fix parens issue for lastmonth
  • Loading branch information
Hridoy Roy authored Jun 3, 2022
1 parent 802ba78 commit 1575454
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions vault/activity_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -1719,14 +1719,13 @@ func modifyResponseMonths(months []*ResponseMonth, start time.Time, end time.Tim
return months
}
start = timeutil.StartOfMonth(start)
end = timeutil.EndOfMonth(end)
if timeutil.IsCurrentMonth(end, time.Now().UTC()) {
end = timeutil.StartOfMonth(end).AddDate(0, -1, 0)
end = timeutil.EndOfMonth(timeutil.StartOfMonth(end).AddDate(0, -1, 0))
}
end = timeutil.EndOfMonth(end)
modifiedResponseMonths := make([]*ResponseMonth, 0)
firstMonth, err := time.Parse(time.RFC3339, months[0].Timestamp)
lastMonth, err2 := time.Parse(time.RFC3339, months[len(months)-1].Timestamp)
if err != nil || err2 != nil {
if err != nil {
return months
}
for start.Before(firstMonth) {
Expand All @@ -1735,8 +1734,13 @@ func modifyResponseMonths(months []*ResponseMonth, start time.Time, end time.Tim
start = timeutil.StartOfMonth(start.AddDate(0, 1, 0))
}
modifiedResponseMonths = append(modifiedResponseMonths, months...)
lastMonthStart, err := time.Parse(time.RFC3339, modifiedResponseMonths[len(modifiedResponseMonths)-1].Timestamp)
if err != nil {
return modifiedResponseMonths
}
lastMonth := timeutil.EndOfMonth(lastMonthStart)
for lastMonth.Before(end) {
lastMonth = timeutil.StartOfMonth(lastMonth.AddDate(0, 1, 0))
lastMonth = timeutil.StartOfMonth(lastMonth).AddDate(0, 1, 0)
monthPlaceholder := &ResponseMonth{Timestamp: lastMonth.UTC().Format(time.RFC3339)}
modifiedResponseMonths = append(modifiedResponseMonths, monthPlaceholder)

Expand Down

0 comments on commit 1575454

Please sign in to comment.