-
Notifications
You must be signed in to change notification settings - Fork 441
/
time_test.go
61 lines (52 loc) · 1.74 KB
/
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
55
56
57
58
59
60
61
package saml
import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
)
func TestRelaxedTimeFormat(t *testing.T) {
rt := time.Date(1981, 02, 03, 14, 15, 16, 17, time.UTC)
assert.Check(t, is.Equal("1981-02-03T14:15:16Z", RelaxedTime(rt).String()))
buf, err := RelaxedTime(rt).MarshalText()
assert.Check(t, err)
assert.Check(t, is.Equal("1981-02-03T14:15:16Z", string(buf)))
loc, err := time.LoadLocation("America/New_York")
assert.Check(t, err)
rt = time.Date(1981, 02, 03, 9, 15, 16, 17, loc)
assert.Check(t, is.Equal("1981-02-03T14:15:16Z", RelaxedTime(rt).String()))
buf, err = RelaxedTime(rt).MarshalText()
assert.Check(t, err)
assert.Check(t, is.Equal("1981-02-03T14:15:16Z", string(buf)))
}
func TestRelaxedTimeParse(t *testing.T) {
{
var rt RelaxedTime
err := rt.UnmarshalText([]byte("1981-02-03T14:15:16Z"))
assert.Check(t, err)
assert.Check(t, is.DeepEqual(
RelaxedTime(time.Date(1981, 02, 03, 14, 15, 16, 0, time.UTC)),
rt, cmp.AllowUnexported(RelaxedTime{})))
}
{
var rt RelaxedTime
err := rt.UnmarshalText([]byte("1981-02-03T14:15:16.178901234Z"))
assert.Check(t, err)
assert.Check(t, is.DeepEqual(RelaxedTime(time.Date(1981, 02, 03, 14, 15, 16, 179000000, time.UTC)),
rt, cmp.AllowUnexported(RelaxedTime{})))
}
{
var rt RelaxedTime
err := rt.UnmarshalText([]byte("1981-02-03T14:15:16.1717Z"))
assert.Check(t, err)
assert.Check(t, is.DeepEqual(RelaxedTime(time.Date(1981, 02, 03, 14, 15, 16, 172000000, time.UTC)),
rt, cmp.AllowUnexported(RelaxedTime{})))
}
{
var rt RelaxedTime
err := rt.UnmarshalText([]byte("1981-02-03T14:15:16Z04:00"))
assert.Check(t, is.Error(err,
"parsing time \"1981-02-03T14:15:16Z04:00\": extra text: \"04:00\""))
}
}