-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtime_test.go
72 lines (67 loc) · 2.09 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
62
63
64
65
66
67
68
69
70
71
72
package rrule
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseTime(t *testing.T) {
cases := []struct {
Input string
DefaultLoc *time.Location
Expected time.Time
ExpectedFloating bool
}{
{
Input: "20181027T183615",
Expected: time.Date(2018, time.October, 27, 18, 36, 15, 00, time.UTC),
ExpectedFloating: true,
},
{
Input: "DTSTART=20181027T183615",
DefaultLoc: NewYork(),
Expected: time.Date(2018, time.October, 27, 18, 36, 15, 00, NewYork()),
ExpectedFloating: true,
},
{
Input: "DTSTART=20181027T183615Z",
DefaultLoc: NewYork(),
Expected: time.Date(2018, time.October, 27, 18, 36, 15, 00, time.UTC),
ExpectedFloating: false,
},
{
Input: "DTSTART=20181027T183615-0500",
DefaultLoc: NewYork(),
Expected: time.Date(2018, time.October, 27, 18, 36, 15, 00, time.FixedZone("-0500", int(-5*time.Hour/time.Second))),
ExpectedFloating: false,
},
{
Input: "DTSTART;TZID=America/New_York:20181027T183615",
Expected: time.Date(2018, time.October, 27, 18, 36, 15, 00, NewYork()),
ExpectedFloating: false,
},
{
Input: "UNTIL;TZID=America/New_York:20181027T183615Z",
Expected: time.Date(2018, time.October, 27, 18, 36, 15, 00, time.UTC),
ExpectedFloating: false,
},
{
Input: "DTSTART;TZID=America/New_York:20071104T013000",
Expected: time.Date(2007, time.November, 4, 1, 30, 0, 0, NewYork()),
ExpectedFloating: false,
},
{
Input: "DTSTART;TZID=America/New_York:20070311T023000",
Expected: time.Date(2007, time.March, 11, 3, 30, 0, 0, NewYork()),
ExpectedFloating: false,
},
}
for _, tc := range cases {
t.Run(tc.Input, func(t *testing.T) {
got, gotFloating, err := parseTime(tc.Input, tc.DefaultLoc)
require.NoError(t, err)
assert.True(t, tc.Expected.Equal(got), tc.Expected, got)
assert.Equal(t, tc.ExpectedFloating, gotFloating)
})
}
}