aboutsummaryrefslogtreecommitdiff
path: root/cisa/date.go
diff options
context:
space:
mode:
Diffstat (limited to 'cisa/date.go')
-rw-r--r--cisa/date.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/cisa/date.go b/cisa/date.go
index b36b73c..b3b6528 100644
--- a/cisa/date.go
+++ b/cisa/date.go
@@ -1,6 +1,7 @@
package cisa
import (
+ "encoding/json"
"fmt"
"regexp"
"strconv"
@@ -135,5 +136,29 @@ func (me Date) String() string {
y, m, d := me.GetComponents()
// return string
- return fmt.Sprintf("%d-%d-%d", y, m, d)
+ return fmt.Sprintf("%04d-%02d-%02d", y, m, d)
+}
+
+// Unmarshal date from JSON string.
+func (me *Date) UnmarshalJSON(b []byte) error {
+ // decode json string
+ var s string
+ if err := json.Unmarshal(b, &s); err != nil {
+ return err
+ }
+
+ // create date
+ d, err := NewDate([]byte(s))
+ if err != nil {
+ return err
+ }
+
+ // save result, return success
+ *me = d
+ return nil
+}
+
+// Marshal Date as JSON string.
+func (d Date) MarshalJSON() ([]byte, error) {
+ return json.Marshal(d.String())
}