Browse Source

增加方法

wangchuanjin 2 years ago
parent
commit
14ff3cf622
1 changed files with 20 additions and 1 deletions
  1. 20 1
      p/public.go

+ 20 - 1
p/public.go

@@ -700,7 +700,7 @@ func IdentityByEntUserId(base, main *Mysql, entUserId int64) *IdentityInfo {
 	return nil
 }
 
-//
+//格式化小时
 func HourFormat(hour int) string {
 	if hour < 10 {
 		return fmt.Sprintf("0%d:00")
@@ -708,3 +708,22 @@ func HourFormat(hour int) string {
 		return fmt.Sprintf("%d:00")
 	}
 }
+
+//数组中的小时是否结束
+func TimesIsOver(times []string, hour int) (bool, time.Time, time.Time) {
+	sort.Strings(times)
+	if len(times) == 0 {
+		return false, nil, nil
+	}
+	lastHour := util.IntAll(strings.Split(times[len(times)-1], ":"))
+	now := time.Now()
+	//跨天
+	if lastHour == 23 && hour == 0 {
+		start := time.Date(now.Year(), now.Month(), now.Day()-1, 0, 0, 0, 0, time.Local)
+		end := time.Date(now.Year(), now.Month(), now.Day()-1, 23, 59, 59, 0, time.Local)
+		return true, start, end
+	} else {
+		start := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local)
+		return hour > lastHour, start, now
+	}
+}