mirror of
https://gitee.com/dromara/carbon.git
synced 2024-11-29 18:57:37 +08:00
Fix issue #246
This commit is contained in:
parent
35cd97125f
commit
d76b2d52ec
@ -509,7 +509,7 @@ func (l Lunar) IsPigYear() bool {
|
||||
}
|
||||
|
||||
func (g Gregorian) diffInDays(t time.Time) int {
|
||||
return int(g.Time.Sub(t).Hours() / 24)
|
||||
return int(g.Time.Truncate(time.Hour).Sub(t).Hours() / 24)
|
||||
}
|
||||
|
||||
func (l Lunar) getOffsetInYear() int {
|
||||
|
@ -1772,3 +1772,46 @@ func TestLunar_IsPigYear(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/golang-module/carbon/issues/246
|
||||
func TestCarbon_Issue246(t *testing.T) {
|
||||
type args struct {
|
||||
g Gregorian
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "case1",
|
||||
args: args{FromGregorian(time.Date(2024, 9, 21, 0, 0, 0, 0, time.Local))},
|
||||
want: "2024-08-19 00:00:00",
|
||||
},
|
||||
{
|
||||
name: "case2",
|
||||
args: args{FromGregorian(time.Date(2024, 9, 21, 23, 50, 0, 0, time.Local))},
|
||||
want: "2024-08-19 23:50:00",
|
||||
},
|
||||
{
|
||||
name: "case3",
|
||||
args: args{FromGregorian(time.Date(2024, 9, 21, 23, 54, 0, 0, time.Local))},
|
||||
want: "2024-08-19 23:54:00",
|
||||
},
|
||||
{
|
||||
name: "case4",
|
||||
args: args{FromGregorian(time.Date(2024, 9, 21, 23, 55, 0, 0, time.Local))},
|
||||
want: "2024-08-19 23:55:00",
|
||||
},
|
||||
{
|
||||
name: "case5",
|
||||
args: args{FromGregorian(time.Date(2024, 9, 21, 23, 59, 0, 0, time.Local))},
|
||||
want: "2024-08-19 23:59:00",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equalf(t, tt.want, (tt.args.g).ToLunar().String(), "args{%v}", tt.args.g)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user