-
Notifications
You must be signed in to change notification settings - Fork 3
/
ctimefmt_test.go
39 lines (33 loc) · 942 Bytes
/
ctimefmt_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
package ctimefmt
import "time"
import "testing"
var format1 string = "%Y-%m-%d %H:%M:%S.%f"
var format2 string = "%Y-%m-%d %l:%M:%S.%L %P, %a"
var value1 string = "2019-01-02 15:04:05.666666"
var value2 string = "2019-01-02 3:04:05.666 pm, Wed"
var dt1 time.Time = time.Date(2019, 1, 2, 15, 4, 5, 666666000, time.UTC)
var dt2 time.Time = time.Date(2019, 1, 2, 15, 4, 5, 666000000, time.UTC)
func TestFormat(t *testing.T) {
s := Format(format1, dt1)
if s != value1 {
t.Errorf("Given: %v, expected: %v", s, value1)
}
s = Format(format2, dt1)
if s != value2 {
t.Errorf("Given: %v, expected: %v", s, value2)
}
}
func TestParse(t *testing.T) {
dt_, err := Parse(format1, value1)
if err != nil {
t.Error(err)
} else if dt_ != dt1 {
t.Errorf("Given: %v, expected: %v", dt_, dt1)
}
dt_, err = Parse(format2, value2)
if err != nil {
t.Error(err)
} else if dt_ != dt2 {
t.Errorf("Given: %v, expected: %v", dt_, dt2)
}
}