-
Notifications
You must be signed in to change notification settings - Fork 9
/
time_test.go
54 lines (46 loc) · 995 Bytes
/
time_test.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
package vitotrol
import (
"encoding/xml"
"testing"
"time"
td "github.com/maxatome/go-testdeep"
)
func TestTime(tt *testing.T) {
t := td.NewT(tt)
// UnmarshalXML
type Value struct {
XMLName xml.Name `xml:"Test"`
Value string `xml:"Wert"`
Time Time `xml:"Zeitstempel"`
}
var value Value
err := xml.Unmarshal(
[]byte(`
<Test>
<Wert>1</Wert>
<Zeitstempel>2016-10-30 22:57:18</Zeitstempel>
</Test>`),
&value)
if t.CmpNoError(err) {
t.CmpDeeply(
value.Time,
Time(time.Date(2016, time.October, 30, 22, 57, 18, 0, vitodataTZ)))
}
err = xml.Unmarshal(
[]byte(`
<Test>
<Wert>1</Wert>
<Zeitstempel>
</Test>`),
&value)
t.CmpError(err)
// String
tm := Time(time.Date(2016, time.October, 30, 22, 57, 18, 0, vitodataTZ))
t.CmpDeeply(tm.String(), "2016-10-30 22:57:18")
tm2, err := ParseVitotrolTime("2016-10-30 22:57:18")
if t.CmpNoError(err) {
t.CmpDeeply(tm2, tm)
}
_, err = ParseVitotrolTime("2016-10-30 22:57:foo")
t.CmpError(err)
}