-
Notifications
You must be signed in to change notification settings - Fork 27
/
datetime_test.go
106 lines (80 loc) · 2.64 KB
/
datetime_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package kolpa
import (
"reflect"
"testing"
"time"
)
func TestDatetime(t *testing.T) {
k := C()
afterD := time.Date(0, 1, 0, 0, 0, 0, 0, time.UTC)
beforeD := time.Date(2018, 1, 0, 0, 0, 0, 0, time.UTC)
afterDString := "2011-01-01T00:00:00.000Z"
beforeDString := "2018-01-01T00:00:00.000Z"
wrongBeforeDString := "wrongtime"
wrongAfterDString := "wrongtime"
ty := reflect.TypeOf(time.Time{}).Kind()
dt := k.DateTimeBetweenWithString(afterDString, beforeDString)
typeOfOutput := reflect.TypeOf(dt).Kind()
if typeOfOutput != ty {
t.Errorf("DateTimeBetweenWithString generation is failed.")
}
dt = k.DateTimeBetweenWithString(wrongAfterDString, wrongBeforeDString)
typeOfOutput = reflect.TypeOf(dt).Kind()
if typeOfOutput != ty {
t.Errorf("DateTimeBetweenWithString generation is failed.")
}
dt = k.DateTimeBetween(afterD, beforeD)
typeOfOutput = reflect.TypeOf(dt).Kind()
if typeOfOutput != ty {
t.Errorf("DateTimeBetween generation is failed.")
}
dt = k.DateTimeAfter(afterD)
typeOfOutput = reflect.TypeOf(dt).Kind()
if typeOfOutput != ty {
t.Errorf("DateTimeAfter generation is failed.")
}
dt = k.DateTimeAfterWithString(afterDString)
typeOfOutput = reflect.TypeOf(dt).Kind()
if typeOfOutput != ty {
t.Errorf("DateTimeAfterWithString generation is failed.")
}
dt = k.DateTimeAfterWithString(wrongAfterDString)
typeOfOutput = reflect.TypeOf(dt).Kind()
if typeOfOutput != ty {
t.Errorf("DateTimeAfterWithString generation is failed.")
}
dt = k.DateTimeBefore(beforeD)
typeOfOutput = reflect.TypeOf(dt).Kind()
if typeOfOutput != ty {
t.Errorf("DateTimeBefore generation is failed.")
}
dt = k.DateTimeBeforeWithString(beforeDString)
typeOfOutput = reflect.TypeOf(dt).Kind()
if typeOfOutput != ty {
t.Errorf("DateTimeBeforeWithString generation is failed.")
}
dt = k.DateTimeBeforeWithString(wrongBeforeDString)
typeOfOutput = reflect.TypeOf(dt).Kind()
if typeOfOutput != ty {
t.Errorf("DateTimeBeforeWithString generation is failed.")
}
dt = k.DateTimeBeforeWithString(wrongBeforeDString)
typeOfOutput = reflect.TypeOf(dt).Kind()
if typeOfOutput != ty {
t.Errorf("DateTimeBeforeWithString generation is failed.")
}
dateString := k.DateFormatter("2006-01-02 15:04:05", k.DateTimeAfterWithString(afterDString).UTC().String())
typeOfOutput = reflect.TypeOf(dateString).Kind()
if typeOfOutput != reflect.String {
t.Errorf("DateFormatter generation is failed.")
}
func() {
defer func() {
if r := recover(); r == nil {
t.Errorf("DateFormatter should have failed.")
}
}()
dateString := k.DateFormatter("2006-01-02 15:04:05", wrongAfterDString)
typeOfOutput = reflect.TypeOf(dateString).Kind()
}()
}