(timeStr string)
| 51 | } |
| 52 | |
| 53 | func parseAndGenerateRandomTime(timeStr string) uint32 { |
| 54 | timeStr = strings.TrimSpace(strings.TrimSuffix(strings.TrimPrefix(timeStr, "{"), "}")) |
| 55 | |
| 56 | t, err := strconv.Atoi(timeStr[:len(timeStr)-1]) |
| 57 | panicIfErr(err) |
| 58 | |
| 59 | unit, ok := unitToSeconds[timeStr[len(timeStr)-1:]] |
| 60 | if !ok { |
| 61 | panic(fmt.Sprintf("unit %s not supported", timeStr[len(timeStr)-1:])) |
| 62 | } |
| 63 | |
| 64 | duration := time.Duration(t) * unit |
| 65 | start := now.Add(-duration) |
| 66 | |
| 67 | return uint32(start.Unix() + random.Int63n(int64(duration.Seconds()))) |
| 68 | } |
| 69 | |
| 70 | func panicIfErr(err error) { |
| 71 | if err != nil { |
no test coverage detected