File: generalizedTime_test.go

package info (click to toggle)
golang-gopkg-asn1-ber.v1 1.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 380 kB
  • sloc: makefile: 5
file content (85 lines) | stat: -rw-r--r-- 1,819 bytes parent folder | download | duplicates (2)
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, 05, 27, 0, time.UTC),
			nil,
		},
		{
			"201702221905Z",
			time.Date(2017, time.Month(2), 22, 19, 05, 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, 05, 27, 123*1000*1000, time.UTC),
			nil,
		},
		{
			"20170222190527,123Z",
			time.Date(2017, time.Month(2), 22, 19, 05, 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)
			}
		}
	}
}