常用类型及数据操作方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
729 B

  1. package helper
  2. import (
  3. "strconv"
  4. "strings"
  5. "time"
  6. )
  7. /**
  8. * 星期几索引化
  9. * 2021/02/24
  10. * gz
  11. */
  12. func GetWeekday() string {
  13. week := []string{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
  14. var index int
  15. today := time.Now().Weekday().String()
  16. for key, day := range week {
  17. if day == today {
  18. index = key
  19. break
  20. }
  21. }
  22. return strconv.Itoa(index)
  23. }
  24. /**
  25. * 今天是否可用
  26. * weekdays 0,1,2,4
  27. * 2021/02/24
  28. * gz
  29. */
  30. func TodayCanUse(weekdays string) bool {
  31. if weekdays == "" {
  32. return true
  33. }
  34. days := strings.Split(weekdays, ",")
  35. var can bool = false
  36. today := GetWeekday()
  37. for _, day := range days {
  38. if today == day {
  39. can = true
  40. break
  41. }
  42. }
  43. return can
  44. }