slice_test.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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(1727366400)
  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. //var roolDay = time.Now().Unix()
  22. var roolDay = int64(1727337600)
  23. for i := 0; i < 10; i++ {
  24. RefreshRoll(&roolDay)
  25. }
  26. }
  27. func RefreshRoll(roolDay *int64) bool {
  28. arr := []string{"8", "16", "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 := 24
  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) && isToday {
  46. *roolDay = currentTime
  47. fmt.Println(" execute ==> num := p.Item[ItemRoll].AddSameTwo()")
  48. return true
  49. }
  50. return false
  51. }