AddQuarters(-1) incorrect result
jiekun opened this issue · comments
Zhu Jiekun commented
Hi.
func TestCarbon(t *testing.T) {
endDate := carbon.Parse("2023-12-31 23:59:59")
endDate = endDate.AddQuarters(-1)
fmt.Println(endDate)
}
the printed result is 2023-10-01 23:59:59
May I ask if it's expected?
peleus commented
AddQuarters(-1) = AddMonths(-3),in theory, 2023-12-31 23:59:59
was 2023-09-31 23:59:59
three months ago, but there were no 31 days in September
peleus commented
If you want to get 2023-09-30 23:59:59
, you can use AddQuartersNoOverflow(-1)
or SubQuartersNoOverflow(1)
Zhu Jiekun commented
Thank you so much for your hint. The explanation is clear. And I'm going to use AddQuartersNoOverflow
.