diff pkg/models/common.go @ 2150:2c67c51d57ad

Print templates: Implemented GET of all templates.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 08 Feb 2019 11:31:57 +0100
parents ae0021feaac8
children 97bba8b51b9c
line wrap: on
line diff
--- a/pkg/models/common.go	Fri Feb 08 11:03:12 2019 +0100
+++ b/pkg/models/common.go	Fri Feb 08 11:31:57 2019 +0100
@@ -34,24 +34,42 @@
 
 type (
 	Date struct{ time.Time }
+	Time struct{ time.Time }
+
 	// Country is a valid country 2 letter code.
 	Country string
 	// UniqueCountries is a list of unique countries.
 	UniqueCountries []Country
 )
 
-func (srd Date) MarshalJSON() ([]byte, error) {
-	return json.Marshal(srd.Format(common.DateFormat))
+func (d Date) MarshalJSON() ([]byte, error) {
+	return json.Marshal(d.Format(common.DateFormat))
 }
 
-func (srd *Date) UnmarshalJSON(data []byte) error {
+func (d *Date) UnmarshalJSON(data []byte) error {
 	var s string
 	if err := json.Unmarshal(data, &s); err != nil {
 		return err
 	}
-	d, err := time.Parse(common.DateFormat, s)
+	d2, err := time.Parse(common.DateFormat, s)
 	if err == nil {
-		*srd = Date{d}
+		*d = Date{d2}
+	}
+	return err
+}
+
+func (t Time) MarshalJSON() ([]byte, error) {
+	return json.Marshal(t.Format(common.TimeFormat))
+}
+
+func (t *Time) UnmarshalJSON(data []byte) error {
+	var s string
+	if err := json.Unmarshal(data, &s); err != nil {
+		return err
+	}
+	t2, err := time.Parse(common.TimeFormat, s)
+	if err == nil {
+		*t = Time{t2}
 	}
 	return err
 }