1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

新增判断是否是周末的方法 (#105)

* 新增判断是否是周末的方法

* 新增判断是否是周末的方法

---------

Co-authored-by: huangxingming <huangxingming@kezaihui.com>
This commit is contained in:
hhhhhxm
2023-05-31 17:05:20 +08:00
committed by GitHub
parent 09ec5b97a6
commit 69b32fd043
2 changed files with 20 additions and 0 deletions

View File

@@ -247,3 +247,7 @@ func DayOfYear(t time.Time) int {
return int(nowDate.Sub(firstDay).Hours() / 24)
}
func IsWeekend(t1 time.Time) bool {
return time.Saturday == t1.Weekday() || time.Sunday == t1.Weekday()
}

View File

@@ -286,3 +286,19 @@ func TestDayOfYear(t *testing.T) {
result3 := DayOfYear(date3)
assert.Equal(0, result3)
}
func TestIsWeekend(t *testing.T) {
assert := internal.NewAssert(t, "TestIsWeekend")
date := time.Date(2023, 06, 03, 0, 0, 0, 0, time.Local)
result := IsWeekend(date)
assert.Equal(true, result)
date1 := time.Date(2023, 06, 04, 0, 0, 0, 0, time.Local)
result1 := IsWeekend(date1)
assert.Equal(true, result1)
date2 := time.Date(2023, 06, 02, 0, 0, 0, 0, time.Local)
result2 := IsWeekend(date2)
assert.Equal(false, result2)
}