修复年龄计算错误的 bug

This commit is contained in:
Peleus 2023-10-09 09:47:53 +08:00
parent b88ad25bd8
commit 4f7b402a16

View File

@ -14,7 +14,7 @@ func (c Carbon) DiffInYears(carbon ...Carbon) int64 {
}
dy, dm, dd := end.Year()-start.Year(), end.Month()-start.Month(), end.Day()-start.Day()
if dd < 0 || dm < 0 {
if dm < 0 || (dm == 0 && dd < 0) {
dy--
}
if dy < 0 && (dd != 0 || dm != 0) {