@@ -78,7 +78,8 @@ func newDefaultFiller() *Filler {
7878 funcs [reflect .Uint64 ] = funcs [reflect .Uint ]
7979
8080 funcs [reflect .String ] = func (field * FieldData ) {
81- field .Value .SetString (field .TagValue )
81+ tagValue := parseDateTimeString (field .TagValue )
82+ field .Value .SetString (tagValue )
8283 }
8384
8485 funcs [reflect .Struct ] = func (field * FieldData ) {
@@ -135,3 +136,40 @@ func newDefaultFiller() *Filler {
135136
136137 return & Filler {FuncByKind : funcs , FuncByType : types , Tag : "default" }
137138}
139+
140+ func parseDateTimeString (data string ) string {
141+
142+ pattern := regexp .MustCompile (`\{\{(\w+\:(?:-|)\d*,(?:-|)\d*,(?:-|)\d*)\}\}` )
143+ matches := pattern .FindAllStringSubmatch (data , - 1 ) // matches is [][]string
144+ for _ , match := range matches {
145+
146+ tags := strings .Split (match [1 ], ":" )
147+ if len (tags ) == 2 {
148+
149+ valueStrings := strings .Split (tags [1 ], "," )
150+ if len (valueStrings ) == 3 {
151+ var values [3 ]int
152+ for key , valueString := range valueStrings {
153+ num , _ := strconv .ParseInt (valueString , 10 , 64 )
154+ values [key ] = int (num )
155+ }
156+
157+ switch tags [0 ] {
158+
159+ case "date" :
160+ str := time .Now ().AddDate (values [0 ], values [1 ], values [2 ]).Format ("2006-01-02" )
161+ data = strings .Replace (data , match [0 ], str , - 1 )
162+ break
163+ case "time" :
164+ str := time .Now ().Add ((time .Duration (values [0 ]) * time .Hour ) +
165+ (time .Duration (values [1 ]) * time .Minute ) +
166+ (time .Duration (values [2 ]) * time .Second )).Format ("15:04:05" )
167+ data = strings .Replace (data , match [0 ], str , - 1 )
168+ break
169+ }
170+ }
171+ }
172+
173+ }
174+ return data
175+ }
0 commit comments