fix bug with year roll over
This commit is contained in:
parent
93ac14f539
commit
e8e183fae6
|
@ -206,11 +206,17 @@ func (d Date) Add(days int) Date {
|
|||
}
|
||||
|
||||
func (d Date) AddMonths(addMonths int) Date {
|
||||
year, month, day := d.t.Date()
|
||||
addYears := int((int(month) + addMonths) / 12)
|
||||
newMonth := (int(month) + addMonths) % 12
|
||||
year, mmonth, day := d.t.Date()
|
||||
month := int(mmonth)
|
||||
for m := 1; m <= addMonths; m++ {
|
||||
month += 1
|
||||
if month == 12 {
|
||||
year += 1
|
||||
month = 1
|
||||
}
|
||||
}
|
||||
|
||||
return NewDate(year+addYears, newMonth, day)
|
||||
return NewDate(year, month, day)
|
||||
}
|
||||
|
||||
func (d Date) Equal(ud Date) bool {
|
||||
|
|
|
@ -367,4 +367,12 @@ func TestEveryNMonths(t *testing.T) {
|
|||
}
|
||||
test.Equals(t, false, recur.RecursOn(task.NewDate(2021, 3, 9)))
|
||||
})
|
||||
|
||||
t.Run("bug", func(t *testing.T) {
|
||||
recur := task.EveryNMonths{
|
||||
Start: task.NewDate(2021, 3, 1),
|
||||
N: 1,
|
||||
}
|
||||
test.Equals(t, false, recur.RecursOn(task.NewDate(2021, 11, 3)))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue