github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/testexporter/correctness/time_flag.go (about) 1 package correctness 2 3 import ( 4 "time" 5 ) 6 7 // TimeValue is a model.Time that can be used as a flag. 8 type TimeValue struct { 9 time.Time 10 set bool 11 } 12 13 // NewTimeValue makes a new TimeValue; will round t down to the nearest midnight. 14 func NewTimeValue(t time.Time) TimeValue { 15 return TimeValue{ 16 Time: t, 17 set: true, 18 } 19 } 20 21 // String implements flag.Value 22 func (v TimeValue) String() string { 23 return v.Time.Format(time.RFC3339) 24 } 25 26 // Set implements flag.Value 27 func (v *TimeValue) Set(s string) error { 28 t, err := time.Parse(time.RFC3339, s) 29 if err != nil { 30 return err 31 } 32 v.Time = t 33 v.set = true 34 return nil 35 }