100 lines
2.9 KiB
Go
100 lines
2.9 KiB
Go
|
package common
|
|||
|
|
|||
|
import (
|
|||
|
"fmt"
|
|||
|
"time"
|
|||
|
)
|
|||
|
|
|||
|
// getAttendancePeriod 返回当前考勤周期的起止日期
|
|||
|
func getAttendancePeriod() (start, end time.Time) {
|
|||
|
now := time.Now()
|
|||
|
currentMonth := now.Month()
|
|||
|
currentYear := now.Year()
|
|||
|
|
|||
|
// 如果当前日期在25号(含)之后,考勤周期的开始日期是本月的26号
|
|||
|
if now.Day() > 25 {
|
|||
|
start = time.Date(currentYear, currentMonth, 26, 0, 0, 0, 0, now.Location())
|
|||
|
// 结束日期是下个月的25号
|
|||
|
if currentMonth == time.December {
|
|||
|
end = time.Date(currentYear+1, time.January, 25, 23, 59, 59, 0, now.Location())
|
|||
|
} else {
|
|||
|
end = time.Date(currentYear, currentMonth+1, 25, 23, 59, 59, 0, now.Location())
|
|||
|
}
|
|||
|
return start, end
|
|||
|
} else {
|
|||
|
// 考勤周期的开始日期是上个月的26号
|
|||
|
if currentMonth == time.January {
|
|||
|
start = time.Date(currentYear-1, time.December, 26, 0, 0, 0, 0, now.Location())
|
|||
|
} else {
|
|||
|
start = time.Date(currentYear, currentMonth-1, 26, 0, 0, 0, 0, now.Location())
|
|||
|
}
|
|||
|
// 结束日期是本月的25号
|
|||
|
end = time.Date(currentYear, currentMonth, 25, 23, 59, 59, 0, now.Location())
|
|||
|
return start, end
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// isResignationDateWithinAttendancePeriod 判断离职日期是否在考勤周期之内
|
|||
|
func isResignationDateWithinAttendancePeriod(resignationDateStr string) bool {
|
|||
|
resignationDate, err := time.Parse("2006-01-02", resignationDateStr)
|
|||
|
if err != nil {
|
|||
|
fmt.Println("Error parsing date:", err)
|
|||
|
return false
|
|||
|
}
|
|||
|
|
|||
|
start, end := getAttendancePeriod()
|
|||
|
return !resignationDate.Before(start) && !resignationDate.After(end)
|
|||
|
}
|
|||
|
|
|||
|
// isCollectionMonthWithinAttendancePeriod 判断查询考勤周期是否在考勤周期之内
|
|||
|
func isCollectionMonthWithinAttendancePeriod(resignationDateStr string) bool {
|
|||
|
resignationDate, err := time.Parse("2006-01", resignationDateStr)
|
|||
|
if err != nil {
|
|||
|
fmt.Println("Error parsing date:", err)
|
|||
|
return false
|
|||
|
}
|
|||
|
|
|||
|
start, end := getAttendancePeriod()
|
|||
|
return !resignationDate.Before(start) && !resignationDate.After(end)
|
|||
|
}
|
|||
|
|
|||
|
// IsBeforeOrEqualResignationDateStr 判断 resignationDateStr 是否在当前考勤周期之前或等于当前考勤周期
|
|||
|
func IsBeforeOrEqualResignationDateStr(resignationDateStr string) bool {
|
|||
|
|
|||
|
if resignationDateStr == "" {
|
|||
|
return true
|
|||
|
}
|
|||
|
|
|||
|
if isResignationDateWithinAttendancePeriod(resignationDateStr) {
|
|||
|
return true
|
|||
|
}
|
|||
|
|
|||
|
resignationDate, err := time.Parse("2006-01-02", resignationDateStr)
|
|||
|
if err != nil {
|
|||
|
fmt.Println("Error parsing date:", err)
|
|||
|
return false
|
|||
|
}
|
|||
|
|
|||
|
return !resignationDate.After(time.Now())
|
|||
|
}
|
|||
|
|
|||
|
// IsBeforeOrEqualCollectionMonth 判断 month 是否在当前考勤周期之前或等于当前考勤周期
|
|||
|
func IsBeforeOrEqualCollectionMonth(month string) bool {
|
|||
|
|
|||
|
if month == "" {
|
|||
|
return true
|
|||
|
}
|
|||
|
|
|||
|
if isCollectionMonthWithinAttendancePeriod(month) {
|
|||
|
return true
|
|||
|
}
|
|||
|
|
|||
|
resignationDate, err := time.Parse("2006-01", month)
|
|||
|
if err != nil {
|
|||
|
fmt.Println("Error parsing date:", err)
|
|||
|
return false
|
|||
|
}
|
|||
|
|
|||
|
return !resignationDate.After(time.Now())
|
|||
|
}
|