MCPcopy
hub / github.com/urfave/cli / Set

Method Set

flag_timestamp.go:54–122  ·  view source on GitHub ↗

Below functions are to satisfy the Value interface Parses the string value to timestamp

(value string)

Source from the content-addressed store, hash-verified

52
53// Parses the string value to timestamp
54func (t *timestampValue) Set(value string) error {
55 var timestamp time.Time
56 var err error
57
58 if t.location == nil {
59 t.location = time.UTC
60 }
61
62 if len(t.layouts) == 0 {
63 return errors.New("got nil/empty layouts slice")
64 }
65
66 for _, layout := range t.layouts {
67 var locErr error
68
69 timestamp, locErr = time.ParseInLocation(layout, value, t.location)
70 if locErr != nil {
71 if err == nil {
72 err = locErr
73 continue
74 }
75
76 err = newMultiError(err, locErr)
77 continue
78 }
79
80 err = nil
81 break
82 }
83
84 if err != nil {
85 return err
86 }
87
88 defaultTS, _ := time.ParseInLocation(time.TimeOnly, time.TimeOnly, timestamp.Location())
89
90 n := time.Now().In(timestamp.Location())
91
92 // If format is missing date (or year only), set it explicitly to current
93 if timestamp.Truncate(time.Hour*24).UnixNano() == defaultTS.Truncate(time.Hour*24).UnixNano() {
94 timestamp = time.Date(
95 n.Year(),
96 n.Month(),
97 n.Day(),
98 timestamp.Hour(),
99 timestamp.Minute(),
100 timestamp.Second(),
101 timestamp.Nanosecond(),
102 timestamp.Location(),
103 )
104 } else if timestamp.Year() == 0 {
105 timestamp = time.Date(
106 n.Year(),
107 timestamp.Month(),
108 timestamp.Day(),
109 timestamp.Hour(),
110 timestamp.Minute(),
111 timestamp.Second(),

Callers 1

TestTimestamp_setFunction · 0.95

Calls 1

newMultiErrorFunction · 0.85

Tested by 1

TestTimestamp_setFunction · 0.76