github.com/grafana/pyroscope@v1.18.0/pkg/test/time.go (about) 1 package test 2 3 import ( 4 "crypto/rand" 5 "time" 6 7 "github.com/oklog/ulid/v2" 8 "github.com/prometheus/common/model" 9 ) 10 11 func ULID(t string) string { 12 parsed, _ := time.Parse(time.RFC3339, t) 13 l := ulid.MustNew(ulid.Timestamp(parsed), rand.Reader) 14 return l.String() 15 } 16 17 func UnixMilli(t string) int64 { 18 return Time(t).UnixMilli() 19 } 20 21 func Time(t string) time.Time { 22 x, _ := time.Parse(time.RFC3339, t) 23 return x 24 } 25 26 func Duration(d string) time.Duration { 27 parsed, _ := model.ParseDuration(d) 28 return time.Duration(parsed) 29 }