Skip to content

Commit

Permalink
backport of commit 1575454 (#15787)
Browse files Browse the repository at this point in the history
Co-authored-by: Hridoy Roy <roy@hashicorp.com>
  • Loading branch information
1 parent 51a6782 commit 8081a42
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 8081a42

Please sign in to comment.