-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatevalue.go
More file actions
38 lines (33 loc) · 1.04 KB
/
datevalue.go
File metadata and controls
38 lines (33 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package opts
import (
"cloud.google.com/go/civil"
)
// Date defines a civil.Date option with the specified name and default value.
// The argument d points to a civil.Date variable that will store the value of
// the option. Date will panic if name is not valid or repeats an existing
// option. On the command line, users must use a string in RFC 3339 full-date
// format (e.g., "2025-12-31" or "2024-02-29"). See [civil.ParseDate] for
// details.
func (g *Group) Date(d *civil.Date, name string, defValue civil.Date) {
if err := validateName("Date", name); err != nil {
panic(err)
}
*d = defValue
opt := &opt{
value: &value[civil.Date]{
ptr: d,
convert: civil.ParseDate,
},
name: name,
isBool: false,
}
if err := g.optAlreadySet(name); err != nil {
panic(err)
}
g.opts[name] = opt
}
// DateZero is like Date but it defaults to a zero value. NB: the zero value
// for civil.Date is 0000-00-00, which most programs should not use as is.
func (g *Group) DateZero(d *civil.Date, name string) {
g.Date(d, name, civil.Date{})
}