aboutsummaryrefslogtreecommitdiffstats
path: root/date.go
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2026-05-12 15:35:06 -0400
committerSam Anthony <sam@samanthony.xyz>2026-05-12 15:37:29 -0400
commit9010ebe8a581fb9db7bc6e97d40ff062fb18495f (patch)
tree4301a455762a59d4951507c8a8781e99c6f91c6d /date.go
parent329257be8d9fb05d3dcea49823acea0f878ed52c (diff)
downloadlulu-9010ebe8a581fb9db7bc6e97d40ff062fb18495f.zip
unmarshal GET /print-jobs response
Diffstat (limited to 'date.go')
-rw-r--r--date.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/date.go b/date.go
new file mode 100644
index 0000000..c82769f
--- /dev/null
+++ b/date.go
@@ -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
+}