mirror of
https://gitee.com/dromara/carbon.git
synced 2024-11-29 18:57:37 +08:00
diffInDays -> dd
diffInSeconds -> ds
This commit is contained in:
parent
5a191551bb
commit
3d701d0958
@ -39,7 +39,7 @@ go get -u gitcode.com/dromara/carbon/v2
|
||||
import "gitcode.com/dromara/carbon/v2"
|
||||
```
|
||||
|
||||
`Carbon` 已经捐赠给了 [dromara](https://dromara.org/ "dromara") 组织,仓库地址发生了改变,如果之前用的仓库地址是 `golang-module/carbon`,请在 `go.mod` 里将原地址更换为新地址,或执行如下命令
|
||||
`Carbon` 已经捐赠给了 [dromara](https://dromara.org/ "dromara") 组织,仓库地址发生了改变,如果之前用的路径是 `golang-module/carbon`,请在 `go.mod` 里将原地址更换为新路径,或执行如下命令
|
||||
|
||||
```go
|
||||
go mod edit -replace github.com/golang-module/carbon/v2=github.com/dromara/carbon/v2
|
||||
|
@ -275,22 +275,22 @@ func getDiffInMonths(c1 Carbon, c2 Carbon) int64 {
|
||||
if c1.Month() == c2.Month() && c1.Year() == c2.Year() {
|
||||
return 0
|
||||
}
|
||||
diffInDays := c1.DiffInDays(c2)
|
||||
dd := c1.DiffInDays(c2)
|
||||
start, end := c2, c1
|
||||
reg := -int64(1)
|
||||
if diffInDays > 0 {
|
||||
sign := -int64(1)
|
||||
if dd > 0 {
|
||||
start, end = c1, c2
|
||||
reg = int64(1)
|
||||
sign = int64(1)
|
||||
}
|
||||
months := getMonthsFromMonthToMonth(start, end, 0)
|
||||
return months * reg
|
||||
return months * sign
|
||||
}
|
||||
|
||||
func getMonthsFromMonthToMonth(c1 Carbon, c2 Carbon, months int64) int64 {
|
||||
date := c1.AddDays(c1.DaysInMonth())
|
||||
diffInDays := date.DiffInDays(c2)
|
||||
diffInSeconds := date.DiffInSeconds(c2)
|
||||
if diffInDays < 0 || diffInDays == 0 && diffInSeconds < 0 {
|
||||
dd := date.DiffInDays(c2)
|
||||
ds := date.DiffInSeconds(c2)
|
||||
if dd < 0 || dd == 0 && ds < 0 {
|
||||
return months
|
||||
}
|
||||
months += 1
|
||||
|
Loading…
Reference in New Issue
Block a user