comparison pkg/common/attributes.go @ 2059:ae0021feaac8 unify_imports

Imports: Made stretch import marshable (even if it is not needed).
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 29 Jan 2019 08:28:50 +0100
parents 7d627258e045
children 2c67c51d57ad
comparison
equal deleted inserted replaced
2058:09f9ae3d0526 2059:ae0021feaac8
16 import ( 16 import (
17 "log" 17 "log"
18 "strconv" 18 "strconv"
19 "strings" 19 "strings"
20 "time" 20 "time"
21 )
22
23 const (
24 TimeFormat = "2006-01-02T15:04:05"
25 DateFormat = "2006-01-02"
21 ) 26 )
22 27
23 type ( 28 type (
24 29
25 // Attributes is a map of optional key/value attributes 30 // Attributes is a map of optional key/value attributes
101 v = "false" 106 v = "false"
102 } 107 }
103 return ca.Set(key, v) 108 return ca.Set(key, v)
104 } 109 }
105 110
106 const TimeFormat = "2006-01-02T15:04:05" 111 func (ca Attributes) Date(key string) (time.Time, bool) {
112 s, found := ca.Get(key)
113 if !found {
114 return time.Time{}, false
115 }
116 d, err := time.Parse(DateFormat, s)
117 if err != nil {
118 log.Printf("error: %v\n", err)
119 return time.Time{}, false
120 }
121 return d, true
122 }
123
124 func (ca Attributes) SetDate(key string, date time.Time) bool {
125 s := date.Format(DateFormat)
126 return ca.Set(key, s)
127 }
107 128
108 // Time gives a time.Time for a given key. 129 // Time gives a time.Time for a given key.
109 func (ca Attributes) Time(key string) (time.Time, bool) { 130 func (ca Attributes) Time(key string) (time.Time, bool) {
110 s, found := ca.Get(key) 131 s, found := ca.Get(key)
111 if !found { 132 if !found {