golang-module / carbon

A simple, semantic and developer-friendly golang package for time

Home Page:https://pkg.go.dev/github.com/golang-module/carbon/v2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AddQuarters(-1) incorrect result

jiekun opened this issue · comments

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?

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

If you want to get 2023-09-30 23:59:59, you can use AddQuartersNoOverflow(-1) or SubQuartersNoOverflow(1)

Thank you so much for your hint. The explanation is clear. And I'm going to use AddQuartersNoOverflow.