From 8b6e1e99dfbfe9c5324ba161cfbd742cd5dd5499 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期一, 29 四月 2024 17:47:42 +0800
Subject: [PATCH] 根据规格取纤度等级标准
---
pkg/timex/timex.go | 58 ++++++++++++++++++++++++++++++++++++----------------------
1 files changed, 36 insertions(+), 22 deletions(-)
diff --git a/pkg/timex/timex.go b/pkg/timex/timex.go
index 73a2be9..5fcb5dc 100644
--- a/pkg/timex/timex.go
+++ b/pkg/timex/timex.go
@@ -1,7 +1,6 @@
package timex
import (
- "jialian/constvar"
"time"
)
@@ -58,29 +57,44 @@
return time.Now().Format(timeLayout)
}
-func NextDateTimestamp(base time.Time, unit constvar.InspectCycleUnit, cycle int) time.Time {
- var t time.Time
- switch unit {
- case constvar.InspectCycleUnitWeek:
- t = base.AddDate(0, 0, cycle*7)
- case constvar.InspectCycleUnitMonth:
- t = base.AddDate(0, cycle, 0)
- case constvar.InspectCycleUnitDay:
- t = base.AddDate(0, 0, cycle)
+func GetDate(year int, month time.Month) int {
+ day := 0
+ if month == time.February {
+ if (year%4 == 0 && year%100 != 0) || year%400 == 0 {
+ day = 29
+ } else {
+ day = 28
+ }
+ } else {
+ if month == time.January || month == time.March || month == time.May || month == time.July ||
+ month == time.August || month == time.October || month == time.December {
+ day = 31
+ } else {
+ day = 30
+ }
}
- return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
+ return day
}
-// Cycle2Seconds 鍛ㄦ湡鎹㈢畻鎴愮鏁�
-func Cycle2Seconds(unit constvar.InspectCycleUnit, cycle int) int {
- var s int
- switch unit {
- case constvar.InspectCycleUnitWeek:
- s = cycle * 86400 * 7
- case constvar.InspectCycleUnitMonth:
- s = cycle * 86400 * 30
- case constvar.InspectCycleUnitDay:
- s = cycle * 86400
+// 鑾峰彇涓�涓湀鍐呯殑鎵�鏈夋槦鏈�
+func GetWeeksOfMonth(year int, month time.Month) [][]time.Time {
+ firstDay := time.Date(year, month, 1, 0, 0, 0, 0, time.Local)
+ lastDay := firstDay.AddDate(0, 1, -1) // 涓嬩竴涓湀鐨勭涓�澶╁噺涓�锛屽緱鍒版湰鏈堢殑鏈�鍚庝竴澶�
+
+ weeks := make([][]time.Time, 0)
+ currentWeek := make([]time.Time, 0)
+ current := firstDay
+
+ for !current.After(lastDay) {
+ currentWeek = append(currentWeek, current)
+ current = current.AddDate(0, 0, 1) // 澧炲姞涓�澶�
+
+ // 濡傛灉褰撳墠鍛ㄥ凡缁忔弧浜�7澶╋紝鎴栬�呭凡缁忓埌浜嗘湀鐨勬渶鍚庝竴澶╋紝鍒欎繚瀛樿繖涓�鍛�
+ if len(currentWeek) == 7 || current.After(lastDay) {
+ weeks = append(weeks, currentWeek)
+ currentWeek = make([]time.Time, 0) // 閲嶇疆褰撳墠鍛�
+ }
}
- return s
+
+ return weeks
}
--
Gitblit v1.8.0