diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2026-05-12 15:35:06 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2026-05-12 15:37:29 -0400 |
| commit | 9010ebe8a581fb9db7bc6e97d40ff062fb18495f (patch) | |
| tree | 4301a455762a59d4951507c8a8781e99c6f91c6d /date.go | |
| parent | 329257be8d9fb05d3dcea49823acea0f878ed52c (diff) | |
| download | lulu-9010ebe8a581fb9db7bc6e97d40ff062fb18495f.zip | |
unmarshal GET /print-jobs response
Diffstat (limited to 'date.go')
| -rw-r--r-- | date.go | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -0,0 +1,39 @@ +package lulu + +import ( + "fmt" + "time" +) + +type Date time.Time + +func ParseDate(s string) (Date, error) { + t, err := time.Parse(time.DateOnly, s) + return Date(t), err +} + +func MustParseDate(s string) Date { + d, err := ParseDate(s) + if err != nil { + panic(fmt.Sprintf("lulu.ParseDate(%q): %v", s, err)) + } + return d +} + +func (d Date) String() string { + return time.Time(d).Format(time.DateOnly) +} + +func (d *Date) UnmarshalText(text []byte) error { + nd, err := ParseDate(string(text)) + if err != nil { + return err + } + *d = nd + return nil +} + +func (d Date) MarshalText() ([]byte, error) { + s := time.Time(d).Format(time.DateOnly) + return []byte(s), nil +} |