private/date: MonthsCountSince removed, being unused anymore
Change-Id: I666d29b91bc1283c1abb7c3a70b15417c1289f59
This commit is contained in:
parent
2c47a9b1d9
commit
0dfbdae614
@ -30,20 +30,3 @@ func PeriodToTime(period string) (_ time.Time, err error) {
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// MonthsCountSince calculates the months between now and the createdAtTime time.Time value passed.
|
||||
func MonthsCountSince(from time.Time) int {
|
||||
now := time.Now().UTC()
|
||||
months := 0
|
||||
month := from.Month()
|
||||
for from.Before(now) {
|
||||
from = from.Add(time.Hour * 24)
|
||||
nextMonth := from.Month()
|
||||
if nextMonth != month {
|
||||
months++
|
||||
}
|
||||
month = nextMonth
|
||||
}
|
||||
|
||||
return months
|
||||
}
|
||||
|
@ -47,22 +47,3 @@ func TestPeriodToTime(t *testing.T) {
|
||||
require.Equal(t, periodTime.String(), tc.periodTime.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestMonthsCountSince(t *testing.T) {
|
||||
testCases := [...]struct {
|
||||
date time.Time
|
||||
monthsAmount int
|
||||
}{
|
||||
{time.Date(2020, 2, 13, 0, 0, 0, 0, &time.Location{}), 3},
|
||||
{time.Date(2015, 7, 30, 0, 0, 0, 0, &time.Location{}), 58},
|
||||
{time.Date(2017, 1, 28, 0, 0, 0, 0, &time.Location{}), 40},
|
||||
{time.Date(2016, 11, 1, 0, 0, 0, 0, &time.Location{}), 42},
|
||||
{time.Date(2019, 4, 17, 0, 0, 0, 0, &time.Location{}), 13},
|
||||
{time.Date(2018, 9, 11, 0, 0, 0, 0, &time.Location{}), 20},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
monthDiff := date.MonthsCountSince(tc.date)
|
||||
require.Equal(t, monthDiff, tc.monthsAmount)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user