forked from nleeper/goment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_end_of_test.go
186 lines (125 loc) · 4.54 KB
/
start_end_of_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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package goment
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestStartOfYear(t *testing.T) {
start := time.Date(2012, 1, 1, 0, 0, 0, 0, time.UTC)
lib := simpleString("2012-05-09 14:17:12")
lib.StartOf("year")
assert.Equal(t, simpleTime(start).Format(), lib.Format())
}
func TestStartOfQuarter(t *testing.T) {
start := time.Date(2012, 7, 1, 0, 0, 0, 0, time.UTC)
lib := simpleString("2012-09-15 15:10:55")
lib.StartOf("quarter")
assert.Equal(t, simpleTime(start).Format(), lib.Format())
}
func TestStartOfMonth(t *testing.T) {
start := time.Date(2012, 2, 1, 0, 0, 0, 0, time.UTC)
lib := simpleString("2012-02-28 15:10:55")
lib.StartOf("month")
assert.Equal(t, simpleTime(start).Format(), lib.Format())
}
func TestStartOfWeek(t *testing.T) {
assert.Equal(t, "Sunday", simpleNow().StartOf("week").Format("dddd"))
}
func TestStartOfISOWeek(t *testing.T) {
start := time.Date(2021, 4, 5, 0, 0, 0, 0, time.UTC)
lib := simpleString("2021-04-11 13:45:12")
lib.StartOf("isoWeek")
assert.Equal(t, simpleTime(start).Format(), lib.Format())
}
func TestStartOfDay(t *testing.T) {
start := time.Date(2012, 2, 28, 0, 0, 0, 0, time.UTC)
lib := simpleString("2012-02-28 15:10:55")
lib.StartOf("day")
assert.Equal(t, simpleTime(start).Format(), lib.Format())
}
func TestStartOfDate(t *testing.T) {
start := time.Date(2012, 2, 15, 0, 0, 0, 0, time.UTC)
lib := simpleString("2012-02-15 15:10:55")
lib.StartOf("date")
assert.Equal(t, simpleTime(start).Format(), lib.Format())
}
func TestStartOfHour(t *testing.T) {
start := time.Date(2012, 2, 15, 15, 0, 0, 0, time.UTC)
lib := simpleString("2012-02-15 15:10:55.123456")
lib.StartOf("hour")
assert.Equal(t, simpleTime(start).Format(), lib.Format())
}
func TestStartOfMinute(t *testing.T) {
start := time.Date(2012, 2, 15, 15, 10, 0, 0, time.UTC)
lib := simpleString("2012-02-15 15:10:55.123456")
lib.StartOf("minute")
assert.Equal(t, simpleTime(start).Format(), lib.Format())
}
func TestStartOfSecond(t *testing.T) {
start := time.Date(2012, 2, 15, 15, 10, 55, 0, time.UTC)
lib := simpleString("2012-02-15 15:10:55.123456")
lib.StartOf("second")
assert.Equal(t, simpleTime(start).Format(), lib.Format())
}
func TestEndOfYear(t *testing.T) {
end := time.Date(2012, 12, 31, 23, 59, 59, 999999999, time.UTC)
lib := simpleString("2012-05-09 14:17:12")
lib.EndOf("year")
assert.Equal(t, simpleTime(end).Format(), lib.Format())
}
func TestEndOfQuarter(t *testing.T) {
end := time.Date(2012, 9, 30, 23, 59, 59, 999999999, time.UTC)
lib := simpleString("2012-07-15 15:10:55")
lib.EndOf("quarter")
assert.Equal(t, simpleTime(end).Format(), lib.Format())
}
func TestEndOfMonth(t *testing.T) {
end := time.Date(2011, 2, 28, 23, 59, 59, 999999999, time.UTC)
lib := simpleString("2011-02-01 15:10:55")
lib.EndOf("month")
assert.Equal(t, simpleTime(end).Format(), lib.Format())
}
func TestEndOfWeek(t *testing.T) {
assert.Equal(t, "Saturday", simpleNow().EndOf("week").Format("dddd"))
end := time.Date(2021, 9, 11, 23, 59, 59, 999999999, time.UTC)
lib := simpleString("2021-09-09 13:45:12")
lib.EndOf("week")
assert.Equal(t, simpleTime(end).Format(), lib.Format())
}
func TestEndOfISOWeek(t *testing.T) {
assert.Equal(t, "Sunday", simpleNow().EndOf("isoWeek").Format("dddd"))
end := time.Date(2021, 9, 12, 23, 59, 59, 999999999, time.UTC)
lib := simpleString("2021-09-09 13:45:12")
lib.EndOf("isoWeek")
assert.Equal(t, simpleTime(end).Format(), lib.Format())
}
func TestEndOfDay(t *testing.T) {
end := time.Date(2012, 2, 28, 23, 59, 59, 999999999, time.UTC)
lib := simpleString("2012-02-28 15:10:55")
lib.EndOf("day")
assert.Equal(t, simpleTime(end).Format(), lib.Format())
}
func TestEndOfDate(t *testing.T) {
end := time.Date(2012, 2, 15, 23, 59, 59, 999999999, time.UTC)
lib := simpleString("2012-02-15 15:10:55")
lib.EndOf("date")
assert.Equal(t, simpleTime(end).Format(), lib.Format())
}
func TestEndOfHour(t *testing.T) {
end := time.Date(2012, 2, 15, 15, 59, 59, 999999999, time.UTC)
lib := simpleString("2012-02-15 15:10:55.123456")
lib.EndOf("hour")
assert.Equal(t, simpleTime(end).Format(), lib.Format())
}
func TestEndOfMinute(t *testing.T) {
end := time.Date(2012, 2, 15, 15, 10, 59, 999999999, time.UTC)
lib := simpleString("2012-02-15 15:10:55.123456")
lib.EndOf("minute")
assert.Equal(t, simpleTime(end).Format(), lib.Format())
}
func TestEndOfSecond(t *testing.T) {
end := time.Date(2012, 2, 15, 15, 10, 55, 999999999, time.UTC)
lib := simpleString("2012-02-15 15:10:55.123456")
lib.EndOf("second")
assert.Equal(t, simpleTime(end).Format(), lib.Format())
}