package common import ( "fmt" "time" ) // getAttendancePeriodV2 返回当前考勤周期的起止日期 func getAttendancePeriodV2(month string) (start, end time.Time) { now, _ := time.ParseInLocation("2006-01", month, time.Local) 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 } } // isCollectionMonthWithinAttendancePeriodV2 判断查询考勤周期是否在考勤周期之内 func isCollectionMonthWithinAttendancePeriodV2(resignationDateStr, month, startDate, endDate string) bool { fmt.Println("========================== isCollectionMonthWithinAttendancePeriodV2 =======================================") fmt.Printf("resignationDateStr: %s, month: %s, startDate: %s, endDate: %s\n", resignationDateStr, month, startDate, endDate) fmt.Println("===========================================================================================================") resignationDate, err := time.Parse("2006-01-02", resignationDateStr) if err != nil { fmt.Println("Error parsing date: 3 ", err) return false } if month != "" { start, end := getAttendancePeriodV2(month) fmt.Println("================================ end ============================") if !resignationDate.After(end) && !resignationDate.Before(start) { return true } if resignationDate.After(start) { return true } } if startDate != "" && endDate != "" { startDateT, startDateErr := time.ParseInLocation("2006-01-02", startDate, time.Local) fmt.Println("================================ startDateT ============================") if startDateErr != nil { fmt.Println("Error parsing date: 4 ", startDateErr) return false } endDateT, endDateErr := time.ParseInLocation("2006-01-02", endDate, time.Local) fmt.Println("================================ endDateT ============================") if endDateErr != nil { fmt.Println("Error parsing date: 4 ", endDateErr) return false } if !endDateT.Before(resignationDate) && !startDateT.After(resignationDate) { return true } if startDateT.After(resignationDate) { return false } if resignationDate.After(endDateT) { return true } } return false } // IsBeforeOrEqualCollectionMonthV2 判断 month 是否在当前考勤周期之前或等于当前考勤周期 func IsBeforeOrEqualCollectionMonthV2(resignationDateStr, month, startDate, endDate string) bool { return isCollectionMonthWithinAttendancePeriodV2(resignationDateStr, month, startDate, endDate) }