forked from go-asn1-ber/asn1-ber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generalizedTime_test.go
85 lines (83 loc) · 1.77 KB
/
generalizedTime_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
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
package ber
import (
"testing"
"time"
)
func TestParseGeneralizedTime(t *testing.T) {
for _, test := range []struct {
str string
wanted time.Time
err error
}{
{
"20170222190527Z",
time.Date(2017, time.Month(2), 22, 19, 5, 27, 0, time.UTC),
nil,
},
{
"201702221905Z",
time.Date(2017, time.Month(2), 22, 19, 5, 0, 0, time.UTC),
nil,
},
{
"2017022219Z",
time.Date(2017, time.Month(2), 22, 19, 0, 0, 0, time.UTC),
nil,
},
{
"2017022219.25Z",
time.Date(2017, time.Month(2), 22, 19, 15, 0, 0, time.UTC),
nil,
},
{
"201702221905.25Z",
time.Date(2017, time.Month(2), 22, 19, 5, 15, 0, time.UTC),
nil,
},
{
"20170222190525-0100",
time.Date(2017, time.Month(2), 22, 19, 5, 25, 0, time.FixedZone("", -3600)),
nil,
},
{
"20170222190525+0100",
time.Date(2017, time.Month(2), 22, 19, 5, 25, 0, time.FixedZone("", 3600)),
nil,
},
{
"20170222190525+01",
time.Date(2017, time.Month(2), 22, 19, 5, 25, 0, time.FixedZone("", 3600)),
nil,
},
{
"20170222190527.123Z",
time.Date(2017, time.Month(2), 22, 19, 5, 27, 123*1000*1000, time.UTC),
nil,
},
{
"20170222190527,123Z",
time.Date(2017, time.Month(2), 22, 19, 5, 27, 123*1000*1000, time.UTC),
nil,
},
{
"2017022219-0100",
time.Date(2017, time.Month(2), 22, 19, 0, 0, 0, time.FixedZone("", -3600)),
nil,
},
} {
genTime, err := ParseGeneralizedTime([]byte(test.str))
if err != nil {
if test.err != nil {
if err != test.err {
t.Errorf("unexpected error in %s: %s", test.str, err)
}
} else {
t.Errorf("test %s failed with error: %s", test.str, err)
}
} else {
if !genTime.Equal(test.wanted) {
t.Errorf("test got unexpected result: wanted=%s, got=%s", test.wanted, genTime)
}
}
}
}