slice_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package mhayaSlice
  2. import (
  3. "fmt"
  4. mhayaString "github.com/mhaya/extend/string"
  5. mhayaTime "github.com/mhaya/extend/time"
  6. "slices"
  7. "testing"
  8. "time"
  9. )
  10. //func TestUnique(t *testing.T) {
  11. // list := Unique[string]("1", "2", "3", "1")
  12. // fmt.Println(list)
  13. //}
  14. var currentTime = int64(1727683200)
  15. func TestUniques(t *testing.T) {
  16. //s1 := []string{"1", "2", "3"}
  17. //s2 := []string{"1", "2", "3"}
  18. //
  19. //list := Uniques[string](s1, s2)
  20. //fmt.Println(list)
  21. // 上次恢复时间
  22. var roolDay = int64(1727593200)
  23. for i := 0; i < 10; i++ {
  24. RefreshRoll(&roolDay)
  25. }
  26. }
  27. func RefreshRoll(roolDay *int64) bool {
  28. arr := []string{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"}
  29. slice := make([]int, 0)
  30. for _, s := range arr {
  31. hour, _ := mhayaString.ToInt(s)
  32. slice = append(slice, hour)
  33. }
  34. // 小时数,24小时制
  35. //curHour := time.Now().Hour()
  36. curHour := 16
  37. rollHour := time.Unix(*roolDay, 0).Hour()
  38. isToday := mhayaTime.CreateFromTimestamp(*roolDay).IsToday()
  39. if isToday {
  40. slice = slices.DeleteFunc(slice, func(x int) bool {
  41. return x <= rollHour
  42. })
  43. }
  44. fmt.Println("slice:", slice)
  45. if slices.Contains(slice, curHour) {
  46. *roolDay = currentTime
  47. fmt.Println(" execute ==> num := p.Item[ItemRoll].AddSameTwo()")
  48. return true
  49. }
  50. return false
  51. }