Skip to content

Commit b8f2c93

Browse files
committed
Merge branch 'shuqingzai-sqz-idd'
2 parents cd94c98 + 70d695b commit b8f2c93

128 files changed

Lines changed: 10480 additions & 10068 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22
root = true
33

44
[*]
5-
indent_style = tab
5+
indent_style = space
6+
indent_size = 2
67
charset = utf-8
78
trim_trailing_whitespace = true
9+
insert_final_newline = true
810

911
[*.md]
10-
indent_size = 4
11-
trim_trailing_whitespace = false
12-
13-
[lang/*.json]
14-
indent_size = 4
12+
trim_trailing_whitespace = false

.github/FUNDING.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# These are supported funding model platforms
22

3-
github: gouguoyin
3+
github: #
44
patreon: # Replace with a single Patreon username
55
open_collective: go-carbon
6-
ko_fi: # Replace with a single Ko-fi username
6+
ko_fi: #go-carbon
77
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8-
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9-
liberapay: gouguoyin
10-
issuehunt: dromara/carbon
8+
community_bridge: #go-carbon
9+
liberapay: #go-carbon
10+
issuehunt: #go-carbon
1111
otechie: # Replace with a single Otechie username
1212
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
1313
custom: ['https://www.gouguoyin.com/zanzhu.html']

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# IntelliJ project files
2+
.idea
3+
*.iml
4+
out
5+
gen

README.cn.md

Lines changed: 280 additions & 186 deletions
Large diffs are not rendered by default.

README.jp.md

Lines changed: 242 additions & 138 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 261 additions & 152 deletions
Large diffs are not rendered by default.

boundary.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,11 @@ func (c *Carbon) StartOfWeek() *Carbon {
106106
if c.IsInvalid() {
107107
return c
108108
}
109-
dayOfWeek, weekStartsAt := c.DayOfWeek(), int(c.weekStartsAt)
110-
return c.SubDays((DaysPerWeek + dayOfWeek - weekStartsAt) % DaysPerWeek).StartOfDay()
109+
dayOfWeek, weekStartsAt := c.StdTime().Weekday(), c.WeekStartsAt()
110+
if dayOfWeek == weekStartsAt {
111+
return c.StartOfDay()
112+
}
113+
return c.SubDays(int(DaysPerWeek+dayOfWeek-weekStartsAt) % DaysPerWeek).StartOfDay()
111114
}
112115

113116
// EndOfWeek returns a Carbon instance for end of the week.
@@ -116,8 +119,11 @@ func (c *Carbon) EndOfWeek() *Carbon {
116119
if c.IsInvalid() {
117120
return c
118121
}
119-
dayOfWeek, weekEndsAt := c.DayOfWeek(), int(c.weekStartsAt)+DaysPerWeek-1
120-
return c.AddDays((DaysPerWeek - dayOfWeek + weekEndsAt) % DaysPerWeek).EndOfDay()
122+
dayOfWeek, weekEndsAt := c.StdTime().Weekday(), c.WeekEndsAt()
123+
if dayOfWeek == weekEndsAt {
124+
return c.EndOfDay()
125+
}
126+
return c.AddDays(int(DaysPerWeek-dayOfWeek+weekEndsAt) % DaysPerWeek).EndOfDay()
121127
}
122128

123129
// StartOfDay returns a Carbon instance for start of the day.
@@ -127,7 +133,7 @@ func (c *Carbon) StartOfDay() *Carbon {
127133
return c
128134
}
129135
year, month, day := c.Date()
130-
return create(year, month, day, 0, 0, 0, 0)
136+
return create(year, month, day, 0, 0, 0, 0, c.Timezone())
131137
}
132138

133139
// EndOfDay returns a Carbon instance for end of the day.
@@ -137,7 +143,7 @@ func (c *Carbon) EndOfDay() *Carbon {
137143
return c
138144
}
139145
year, month, day := c.Date()
140-
return create(year, month, day, 23, 59, 59, 999999999)
146+
return create(year, month, day, 23, 59, 59, 999999999, c.Timezone())
141147
}
142148

143149
// StartOfHour returns a Carbon instance for start of the hour.
@@ -147,7 +153,7 @@ func (c *Carbon) StartOfHour() *Carbon {
147153
return c
148154
}
149155
year, month, day := c.Date()
150-
return create(year, month, day, c.Hour(), 0, 0, 0)
156+
return create(year, month, day, c.Hour(), 0, 0, 0, c.Timezone())
151157
}
152158

153159
// EndOfHour returns a Carbon instance for end of the hour.
@@ -157,7 +163,7 @@ func (c *Carbon) EndOfHour() *Carbon {
157163
return c
158164
}
159165
year, month, day := c.Date()
160-
return create(year, month, day, c.Hour(), 59, 59, 999999999)
166+
return create(year, month, day, c.Hour(), 59, 59, 999999999, c.Timezone())
161167
}
162168

163169
// StartOfMinute returns a Carbon instance for start of the minute.
@@ -167,7 +173,7 @@ func (c *Carbon) StartOfMinute() *Carbon {
167173
return c
168174
}
169175
year, month, day, hour, minute, _ := c.DateTime()
170-
return create(year, month, day, hour, minute, 0, 0)
176+
return create(year, month, day, hour, minute, 0, 0, c.Timezone())
171177
}
172178

173179
// EndOfMinute returns a Carbon instance for end of the minute.
@@ -177,7 +183,7 @@ func (c *Carbon) EndOfMinute() *Carbon {
177183
return c
178184
}
179185
year, month, day, hour, minute, _ := c.DateTime()
180-
return create(year, month, day, hour, minute, 59, 999999999)
186+
return create(year, month, day, hour, minute, 59, 999999999, c.Timezone())
181187
}
182188

183189
// StartOfSecond returns a Carbon instance for start of the second.
@@ -187,7 +193,7 @@ func (c *Carbon) StartOfSecond() *Carbon {
187193
return c
188194
}
189195
year, month, day, hour, minute, second := c.DateTime()
190-
return create(year, month, day, hour, minute, second, 0)
196+
return create(year, month, day, hour, minute, second, 0, c.Timezone())
191197
}
192198

193199
// EndOfSecond returns a Carbon instance for end of the second.
@@ -197,5 +203,5 @@ func (c *Carbon) EndOfSecond() *Carbon {
197203
return c
198204
}
199205
year, month, day, hour, minute, second := c.DateTime()
200-
return create(year, month, day, hour, minute, second, 999999999)
206+
return create(year, month, day, hour, minute, second, 999999999, c.Timezone())
201207
}

boundary_bench_test.go

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package carbon
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func BenchmarkCarbon_StartOfCentury(b *testing.B) {
8+
c := Now()
9+
b.ResetTimer()
10+
for n := 0; n < b.N; n++ {
11+
c.StartOfCentury()
12+
}
13+
}
14+
15+
func BenchmarkCarbon_EndOfCentury(b *testing.B) {
16+
c := Now()
17+
b.ResetTimer()
18+
for n := 0; n < b.N; n++ {
19+
c.EndOfCentury()
20+
}
21+
}
22+
23+
func BenchmarkCarbon_StartOfDecade(b *testing.B) {
24+
c := Now()
25+
b.ResetTimer()
26+
for n := 0; n < b.N; n++ {
27+
c.StartOfDecade()
28+
}
29+
}
30+
31+
func BenchmarkCarbon_EndOfDecade(b *testing.B) {
32+
c := Now()
33+
b.ResetTimer()
34+
for n := 0; n < b.N; n++ {
35+
c.EndOfDecade()
36+
}
37+
}
38+
39+
func BenchmarkCarbon_StartOfYear(b *testing.B) {
40+
c := Now()
41+
b.ResetTimer()
42+
for n := 0; n < b.N; n++ {
43+
c.StartOfYear()
44+
}
45+
}
46+
47+
func BenchmarkCarbon_EndOfYear(b *testing.B) {
48+
c := Now()
49+
b.ResetTimer()
50+
for n := 0; n < b.N; n++ {
51+
c.EndOfYear()
52+
}
53+
}
54+
55+
func BenchmarkCarbon_StartOfQuarter(b *testing.B) {
56+
c := Now()
57+
b.ResetTimer()
58+
for n := 0; n < b.N; n++ {
59+
c.StartOfQuarter()
60+
}
61+
}
62+
63+
func BenchmarkCarbon_EndOfQuarter(b *testing.B) {
64+
c := Now()
65+
b.ResetTimer()
66+
for n := 0; n < b.N; n++ {
67+
c.EndOfQuarter()
68+
}
69+
}
70+
71+
func BenchmarkCarbon_StartOfMonth(b *testing.B) {
72+
c := Now()
73+
b.ResetTimer()
74+
for n := 0; n < b.N; n++ {
75+
c.StartOfMonth()
76+
}
77+
}
78+
79+
func BenchmarkCarbon_EndOfMonth(b *testing.B) {
80+
c := Now()
81+
b.ResetTimer()
82+
for n := 0; n < b.N; n++ {
83+
c.EndOfMonth()
84+
}
85+
}
86+
87+
func BenchmarkCarbon_StartOfWeek(b *testing.B) {
88+
c := Now()
89+
b.ResetTimer()
90+
for n := 0; n < b.N; n++ {
91+
c.StartOfWeek()
92+
}
93+
}
94+
95+
func BenchmarkCarbon_EndOfWeek(b *testing.B) {
96+
c := Now()
97+
b.ResetTimer()
98+
for n := 0; n < b.N; n++ {
99+
c.EndOfWeek()
100+
}
101+
}
102+
103+
func BenchmarkCarbon_StartOfDay(b *testing.B) {
104+
c := Now()
105+
b.ResetTimer()
106+
for n := 0; n < b.N; n++ {
107+
c.StartOfDay()
108+
}
109+
}
110+
111+
func BenchmarkCarbon_EndOfDay(b *testing.B) {
112+
c := Now()
113+
b.ResetTimer()
114+
for n := 0; n < b.N; n++ {
115+
c.EndOfDay()
116+
}
117+
}
118+
119+
func BenchmarkCarbon_StartOfHour(b *testing.B) {
120+
c := Now()
121+
b.ResetTimer()
122+
for n := 0; n < b.N; n++ {
123+
c.StartOfHour()
124+
}
125+
}
126+
127+
func BenchmarkCarbon_EndOfHour(b *testing.B) {
128+
c := Now()
129+
b.ResetTimer()
130+
for n := 0; n < b.N; n++ {
131+
c.EndOfHour()
132+
}
133+
}
134+
135+
func BenchmarkCarbon_StartOfMinute(b *testing.B) {
136+
c := Now()
137+
b.ResetTimer()
138+
for n := 0; n < b.N; n++ {
139+
c.StartOfMinute()
140+
}
141+
}
142+
143+
func BenchmarkCarbon_EndOfMinute(b *testing.B) {
144+
c := Now()
145+
b.ResetTimer()
146+
for n := 0; n < b.N; n++ {
147+
c.EndOfMinute()
148+
}
149+
}
150+
151+
func BenchmarkCarbon_StartOfSecond(b *testing.B) {
152+
c := Now()
153+
b.ResetTimer()
154+
for n := 0; n < b.N; n++ {
155+
c.StartOfSecond()
156+
}
157+
}
158+
159+
func BenchmarkCarbon_EndOfSecond(b *testing.B) {
160+
c := Now()
161+
b.ResetTimer()
162+
for n := 0; n < b.N; n++ {
163+
c.EndOfSecond()
164+
}
165+
}

boundary_example_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ func ExampleCarbon_StartOfWeek() {
143143
fmt.Println(carbon.Parse("2020-12-31 23:59:59").StartOfWeek().ToString())
144144

145145
// Output:
146-
// 0000-12-31 00:00:00 +0000 UTC
147-
// 2019-12-29 00:00:00 +0000 UTC
148-
// 2020-08-09 00:00:00 +0000 UTC
149-
// 2020-12-27 00:00:00 +0000 UTC
146+
// 0001-01-01 00:00:00 +0000 UTC
147+
// 2019-12-30 00:00:00 +0000 UTC
148+
// 2020-08-10 00:00:00 +0000 UTC
149+
// 2020-12-28 00:00:00 +0000 UTC
150150
}
151151

152152
func ExampleCarbon_EndOfWeek() {
@@ -156,10 +156,10 @@ func ExampleCarbon_EndOfWeek() {
156156
fmt.Println(carbon.Parse("2020-12-31 23:59:59").EndOfWeek().ToString())
157157

158158
// Output:
159-
// 0001-01-06 23:59:59.999999999 +0000 UTC
160-
// 2020-01-04 23:59:59.999999999 +0000 UTC
161-
// 2020-08-15 23:59:59.999999999 +0000 UTC
162-
// 2021-01-02 23:59:59.999999999 +0000 UTC
159+
// 0001-01-07 23:59:59.999999999 +0000 UTC
160+
// 2020-01-05 23:59:59.999999999 +0000 UTC
161+
// 2020-08-16 23:59:59.999999999 +0000 UTC
162+
// 2021-01-03 23:59:59.999999999 +0000 UTC
163163
}
164164

165165
func ExampleCarbon_StartOfDay() {

0 commit comments

Comments
 (0)