This repository has been archived by the owner on May 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
render_input_time.go
93 lines (79 loc) · 1.82 KB
/
render_input_time.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package form
import (
"fmt"
"time"
)
func (r renderValue) timeInputTime(value time.Time) {
_type := func() (str string) {
switch r._type {
case InputDatetime:
str = "datetime"
case InputDatetimeLocal:
str = "datetime-local"
case InputTime:
str = "time"
case InputDate:
str = "date"
case InputMonth:
str = "month"
case InputWeek:
str = "week"
}
return
}
input := &FirstLayerInput{}
r.fls.append(input)
var attr map[string]string
r.fieldsFns.Call("attr", map[string]interface{}{
"attr": &attr,
})
if attr != nil {
delete(attr, "name")
delete(attr, "type")
delete(attr, "max")
delete(attr, "min")
delete(attr, "step")
input.Attr = attr
} else {
input.Attr = map[string]string{}
}
formatter := func(t time.Time) (str string) {
if t.Unix() != -62135596800 {
switch r._type {
case InputDatetime:
str = fmt.Sprint(t.Format(dateTimeFormat))
case InputDatetimeLocal:
str = fmt.Sprint(t.Format(dateTimeLocalFormat))
case InputTime:
str = fmt.Sprint(t.Format(timeFormat))
case InputDate:
str = fmt.Sprint(t.Format(dateFormat))
case InputMonth:
str = fmt.Sprint(t.Format(monthFormat))
case InputWeek:
year, week := t.ISOWeek()
str = fmt.Sprintf(weekFormat, year, week)
}
}
return
}
input.Attr["name"] = r.preferedName
input.Attr["type"] = _type()
input.Attr["value"] = formatter(value)
min := time.Time{}
max := time.Time{}
_s := ""
r.fieldsFns.Call("range", map[string]interface{}{
"min": &min,
"max": &max,
"minErr": &_s,
"maxErr": &_s,
})
if min.Unix() != -62135596800 {
input.Attr["min"] = formatter(min)
}
if max.Unix() != -62135596800 {
input.Attr["max"] = formatter(max)
}
// Todo: add support for step.
}