We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello,
I encountered an issue with the following code: DiffInMonths is invalid, It's not every month is 30 days
// DiffInMonths gets the difference in months. // 相差多少月 func (c Carbon) DiffInMonths(carbon ...Carbon) int64 { start, end := c, c.Now() if len(carbon) > 0 { end = carbon[len(carbon)-1] } return int64(math.Floor(float64((end.Timestamp() - start.Timestamp()) / (30 * 24 * 3600)))) }
In version 1.6.9, DiffInMonths is right
func (c Carbon) DiffInMonths(carbon ...Carbon) int64 { end := c.Now() if len(carbon) > 0 { end = carbon[len(carbon)-1] } startYear, startMonth, startDay := c.Date() endYear, endMonth, endDay := end.Date() diffYear, diffMonth, diffDay := endYear-startYear, endMonth-startMonth, endDay-startDay if diffDay < 0 { diffMonth = diffMonth - 1 } if diffYear == 0 && diffMonth == 0 { return int64(0) } if diffYear == 0 && diffMonth != 0 && diffDay != 0 { if int(end.DiffAbsInHours(c)) < c.DaysInMonth()*HoursPerDay { return int64(0) } return int64(diffMonth) } return int64(diffYear*MonthsPerYear + diffMonth) }
Thanks!
The text was updated successfully, but these errors were encountered:
The next version will fix
Sorry, something went wrong.
Fixed in version 2.2.4
No branches or pull requests
Hello,
I encountered an issue with the following code:
DiffInMonths is invalid, It's not every month is 30 days
In version 1.6.9, DiffInMonths is right
Thanks!
The text was updated successfully, but these errors were encountered: