You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
610 B
44 lines
610 B
package value
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gitoa.ru/go-4devs/console/input/value/flag"
|
|
)
|
|
|
|
type Duration struct {
|
|
empty
|
|
Val []time.Duration
|
|
Flag flag.Flag
|
|
}
|
|
|
|
func (d *Duration) Append(in string) error {
|
|
v, err := time.ParseDuration(in)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
d.Val = append(d.Val, v)
|
|
|
|
return nil
|
|
}
|
|
|
|
func (d *Duration) Duration() time.Duration {
|
|
if !d.Flag.IsArray() && len(d.Val) == 1 {
|
|
return d.Val[0]
|
|
}
|
|
|
|
return 0
|
|
}
|
|
|
|
func (d *Duration) Durations() []time.Duration {
|
|
return d.Val
|
|
}
|
|
|
|
func (d *Duration) Any() interface{} {
|
|
if d.Flag.IsArray() {
|
|
return d.Durations()
|
|
}
|
|
|
|
return d.Duration()
|
|
}
|
|
|