Skip to content

Commit

Permalink
Prevent quarter ends being assigned to next quarter
Browse files Browse the repository at this point in the history
Previously, this would assign the end of the quarter to the start of the next quarter as the "month count" starts at 1 **and not** 0.

For example, for March, month count: 3, the previous implementation would assign it to quarter 1 ("01_apr_to_jun") as `3/3 == int(1)`. In addition, this would error for the month of December, as the quarter index 4 is not handled.
  • Loading branch information
oliver-hohn committed Dec 26, 2020
1 parent e390542 commit 4e22361
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion organizemyfiles/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ func (f *File) GetQuarter() string {
return Undefined
}

switch quarterIndex := f.CreatedAt.Month() / 3; quarterIndex {
// Month() starts at 1 for January, and ends at 12 for December.
// By subtracting by -1 we can ensure that:
// Jan -> March is 0
// April -> June is 1
// July -> September is 2
// October -> December is 3
switch quarterIndex := (f.CreatedAt.Month() - 1) / 3; quarterIndex {
case 0:
return "00_jan_to_mar"
case 1:
Expand Down

0 comments on commit 4e22361

Please sign in to comment.