Debian Codegraph @

flag_timestamp.go

raw symbols SCIP
1 package cliscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/
2
3 import (
4 "errorsscip-go gomod github.com/golang/go/src go1.22 errors/"
5 "fmtscip-go gomod github.com/golang/go/src go1.22 fmt/"
6 "timescip-go gomod github.com/golang/go/src go1.22 time/"
7 )
8
9 type TimestampFlagscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TimestampFlag# = FlagBasescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/FlagBase#[timescip-go gomod github.com/golang/go/src go1.22 time/.Timescip-go gomod github.com/golang/go/src go1.22 time/Time#, TimestampConfigscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TimestampConfig#, timestampValuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#]
10
11 // TimestampConfig defines the config for timestamp flags
12 type TimestampConfigscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TimestampConfig# struct {
13 Timezonescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TimestampConfig#Timezone. *timescip-go gomod github.com/golang/go/src go1.22 time/.Locationscip-go gomod github.com/golang/go/src go1.22 time/Location#
14 // Available layouts for flag value.
15 //
16 // Note that value for formats with missing year/date will be interpreted as current year/date respectively.
17 //
18 // Read more about time layouts: https://pkg.go.dev/time#pkg-constants
19 Layoutsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TimestampConfig#Layouts. []string
20 }
21
22 // timestampValue wrap to satisfy golang's flag interface.
23 type timestampValuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue# struct {
24 timestampscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#timestamp. *timescip-go gomod github.com/golang/go/src go1.22 time/.Timescip-go gomod github.com/golang/go/src go1.22 time/Time#
25 hasBeenSetscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#hasBeenSet. bool
26 layoutsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#layouts. []string
27 locationscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#location. *timescip-go gomod github.com/golang/go/src go1.22 time/.Locationscip-go gomod github.com/golang/go/src go1.22 time/Location#
28 }
29
30 var _ ValueCreatorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/ValueCreator#[timescip-go gomod github.com/golang/go/src go1.22 time/.Timescip-go gomod github.com/golang/go/src go1.22 time/Time#, TimestampConfigscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TimestampConfig#] = timestampValuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#{}
31
32 // Below functions are to satisfy the ValueCreator interface
33
34 func (t timestampValuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#) Createscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#Create().(val timescip-go gomod github.com/golang/go/src go1.22 time/.Timescip-go gomod github.com/golang/go/src go1.22 time/Time#, p *timescip-go gomod github.com/golang/go/src go1.22 time/.Timescip-go gomod github.com/golang/go/src go1.22 time/Time#, c TimestampConfigscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TimestampConfig#) Valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Value# {
35 *p = val
36 return &timestampValuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#{
37 timestampscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#timestamp.: p,
38 layoutsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#layouts.: c.Layoutsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TimestampConfig#Layouts.,
39 locationscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#location.: c.Timezonescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/TimestampConfig#Timezone.,
40 }
41 }
42
43 func (t timestampValuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#) ToStringscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#ToString().(b timescip-go gomod github.com/golang/go/src go1.22 time/.Timescip-go gomod github.com/golang/go/src go1.22 time/Time#) string {
44 if b.IsZeroscip-go gomod github.com/golang/go/src go1.22 time/Time#IsZero().() {
45 return ""
46 }
47 t.timestampscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#timestamp. = &b
48 return t.Stringscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#String().()
49 }
50
51 // Below functions are to satisfy the Value interface
52
53 // Parses the string value to timestamp
54 func (t *timestampValuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#) Setscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#Set().(value string) error {
55 var timestamp timescip-go gomod github.com/golang/go/src go1.22 time/.Timescip-go gomod github.com/golang/go/src go1.22 time/Time#
56 var err error
57
58 if t.locationscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#location. == nil {
59 t.locationscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#location. = timescip-go gomod github.com/golang/go/src go1.22 time/.UTCscip-go gomod github.com/golang/go/src go1.22 time/UTC.
60 }
61
62 if len(t.layoutsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#layouts.) == 0 {
63 return errorsscip-go gomod github.com/golang/go/src go1.22 errors/.Newscip-go gomod github.com/golang/go/src go1.22 errors/New().("got nil/empty layouts slice")
64 }
65
66 for _, layout := range t.layoutsscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#layouts. {
67 var locErr error
68
69 timestamp, locErr = timescip-go gomod github.com/golang/go/src go1.22 time/.ParseInLocationscip-go gomod github.com/golang/go/src go1.22 time/ParseInLocation().(layout, value, t.locationscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#location.)
70 if locErr != nil {
71 if err == nil {
72 err = locErr
73 continue
74 }
75
76 err = newMultiErrorscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/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, _ := timescip-go gomod github.com/golang/go/src go1.22 time/.ParseInLocationscip-go gomod github.com/golang/go/src go1.22 time/ParseInLocation().(timescip-go gomod github.com/golang/go/src go1.22 time/.TimeOnlyscip-go gomod github.com/golang/go/src go1.22 time/TimeOnly., timescip-go gomod github.com/golang/go/src go1.22 time/.TimeOnlyscip-go gomod github.com/golang/go/src go1.22 time/TimeOnly., timestamp.Locationscip-go gomod github.com/golang/go/src go1.22 time/Time#Location().())
89
90 n := timescip-go gomod github.com/golang/go/src go1.22 time/.Nowscip-go gomod github.com/golang/go/src go1.22 time/Now().().Inscip-go gomod github.com/golang/go/src go1.22 time/Time#In().(timestamp.Locationscip-go gomod github.com/golang/go/src go1.22 time/Time#Location().())
91
92 // If format is missing date (or year only), set it explicitly to current
93 if timestamp.Truncatescip-go gomod github.com/golang/go/src go1.22 time/Time#Truncate().(timescip-go gomod github.com/golang/go/src go1.22 time/.Hourscip-go gomod github.com/golang/go/src go1.22 time/Hour.*24).UnixNanoscip-go gomod github.com/golang/go/src go1.22 time/Time#UnixNano().() == defaultTS.Truncatescip-go gomod github.com/golang/go/src go1.22 time/Time#Truncate().(timescip-go gomod github.com/golang/go/src go1.22 time/.Hourscip-go gomod github.com/golang/go/src go1.22 time/Hour.*24).UnixNanoscip-go gomod github.com/golang/go/src go1.22 time/Time#UnixNano().() {
94 timestamp = timescip-go gomod github.com/golang/go/src go1.22 time/.Datescip-go gomod github.com/golang/go/src go1.22 time/Date().(
95 n.Yearscip-go gomod github.com/golang/go/src go1.22 time/Time#Year().(),
96 n.Monthscip-go gomod github.com/golang/go/src go1.22 time/Time#Month().(),
97 n.Dayscip-go gomod github.com/golang/go/src go1.22 time/Time#Day().(),
98 timestamp.Hourscip-go gomod github.com/golang/go/src go1.22 time/Time#Hour().(),
99 timestamp.Minutescip-go gomod github.com/golang/go/src go1.22 time/Time#Minute().(),
100 timestamp.Secondscip-go gomod github.com/golang/go/src go1.22 time/Time#Second().(),
101 timestamp.Nanosecondscip-go gomod github.com/golang/go/src go1.22 time/Time#Nanosecond().(),
102 timestamp.Locationscip-go gomod github.com/golang/go/src go1.22 time/Time#Location().(),
103 )
104 } else if timestamp.Yearscip-go gomod github.com/golang/go/src go1.22 time/Time#Year().() == 0 {
105 timestamp = timescip-go gomod github.com/golang/go/src go1.22 time/.Datescip-go gomod github.com/golang/go/src go1.22 time/Date().(
106 n.Yearscip-go gomod github.com/golang/go/src go1.22 time/Time#Year().(),
107 timestamp.Monthscip-go gomod github.com/golang/go/src go1.22 time/Time#Month().(),
108 timestamp.Dayscip-go gomod github.com/golang/go/src go1.22 time/Time#Day().(),
109 timestamp.Hourscip-go gomod github.com/golang/go/src go1.22 time/Time#Hour().(),
110 timestamp.Minutescip-go gomod github.com/golang/go/src go1.22 time/Time#Minute().(),
111 timestamp.Secondscip-go gomod github.com/golang/go/src go1.22 time/Time#Second().(),
112 timestamp.Nanosecondscip-go gomod github.com/golang/go/src go1.22 time/Time#Nanosecond().(),
113 timestamp.Locationscip-go gomod github.com/golang/go/src go1.22 time/Time#Location().(),
114 )
115 }
116
117 if t.timestampscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#timestamp. != nil {
118 *t.timestampscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#timestamp. = timestamp
119 }
120 t.hasBeenSetscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#hasBeenSet. = true
121 return nil
122 }
123
124 // String returns a readable representation of this value (for usage defaults)
125 func (t *timestampValuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#) Stringscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#String().() string {
126 return fmtscip-go gomod github.com/golang/go/src go1.22 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.22 fmt/Sprintf().("%v", t.timestampscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#timestamp.)
127 }
128
129 // Get returns the flag structure
130 func (t *timestampValuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#) Getscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#Get().() any {
131 return *t.timestampscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/timestampValue#timestamp.
132 }
133
134 // Timestamp gets the timestamp from a flag name
135 func (cmd *Commandscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#) Timestampscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Timestamp().(name string) timescip-go gomod github.com/golang/go/src go1.22 time/.Timescip-go gomod github.com/golang/go/src go1.22 time/Time# {
136 if v, ok := cmd.Valuescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Value().(name).(timescip-go gomod github.com/golang/go/src go1.22 time/.Timescip-go gomod github.com/golang/go/src go1.22 time/Time#); ok {
137 tracefscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/tracef().("time.Time available for flag name %[1]q with value=%[2]v (cmd=%[3]q)", name, v, cmd.Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.)
138 return v
139 }
140
141 tracefscip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/tracef().("time.Time NOT available for flag name %[1]q (cmd=%[2]q)", name, cmd.Namescip-go gomod github.com/urfave/cli/v3 . `github.com/urfave/cli/v3`/Command#Name.)
142 return timescip-go gomod github.com/golang/go/src go1.22 time/.Timescip-go gomod github.com/golang/go/src go1.22 time/Time#{}
143 }