-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64754b2
commit f2925c6
Showing
3 changed files
with
73 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package helpers | ||
|
||
import ( | ||
"errors" | ||
"time" | ||
) | ||
|
||
// QuarterOf - | ||
func QuarterOf(month time.Month) int { | ||
return (int(month) + 2) / 3 | ||
} | ||
|
||
// QuarterBoundaries - | ||
func QuarterBoundaries(current time.Time) (time.Time, time.Time, error) { | ||
year := current.Year() | ||
quarter := QuarterOf(current.Month()) | ||
|
||
switch quarter { | ||
case 1: | ||
start := time.Date(year, time.January, 1, 0, 0, 0, 0, time.UTC) | ||
end := start.AddDate(0, 3, 0) | ||
return start, end, nil | ||
case 2: | ||
start := time.Date(year, time.April, 1, 0, 0, 0, 0, time.UTC) | ||
end := start.AddDate(0, 3, 0) | ||
return start, end, nil | ||
case 3: | ||
start := time.Date(year, time.July, 1, 0, 0, 0, 0, time.UTC) | ||
end := start.AddDate(0, 3, 0) | ||
return start, end, nil | ||
case 4: | ||
start := time.Date(year, time.October, 1, 0, 0, 0, 0, time.UTC) | ||
end := start.AddDate(0, 3, 0) | ||
return start, end, nil | ||
} | ||
|
||
return time.Now(), time.Now(), errors.New("invalid quarter") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters