@@ -2,72 +2,72 @@ package carbon
2
2
3
3
// StartOfCentury returns a Carbon instance for start of the century.
4
4
// 本世纪开始时间
5
- func (c Carbon ) StartOfCentury () Carbon {
6
- if c .Error != nil {
5
+ func (c * Carbon ) StartOfCentury () * Carbon {
6
+ if c .IsInvalid () {
7
7
return c
8
8
}
9
- return c . create (c .Year ()/ YearsPerCentury * YearsPerCentury , 1 , 1 , 0 , 0 , 0 , 0 )
9
+ return create (c .Year ()/ YearsPerCentury * YearsPerCentury , 1 , 1 , 0 , 0 , 0 , 0 , c . Timezone () )
10
10
}
11
11
12
12
// EndOfCentury returns a Carbon instance for end of the century.
13
13
// 本世纪结束时间
14
- func (c Carbon ) EndOfCentury () Carbon {
15
- if c .Error != nil {
14
+ func (c * Carbon ) EndOfCentury () * Carbon {
15
+ if c .IsInvalid () {
16
16
return c
17
17
}
18
- return c . create (c .Year ()/ YearsPerCentury * YearsPerCentury + 99 , 12 , 31 , 23 , 59 , 59 , 999999999 )
18
+ return create (c .Year ()/ YearsPerCentury * YearsPerCentury + 99 , 12 , 31 , 23 , 59 , 59 , 999999999 , c . Timezone () )
19
19
}
20
20
21
21
// StartOfDecade returns a Carbon instance for start of the decade.
22
22
// 本年代开始时间
23
- func (c Carbon ) StartOfDecade () Carbon {
24
- if c .Error != nil {
23
+ func (c * Carbon ) StartOfDecade () * Carbon {
24
+ if c .IsInvalid () {
25
25
return c
26
26
}
27
- return c . create (c .Year ()/ YearsPerDecade * YearsPerDecade , 1 , 1 , 0 , 0 , 0 , 0 )
27
+ return create (c .Year ()/ YearsPerDecade * YearsPerDecade , 1 , 1 , 0 , 0 , 0 , 0 , c . Timezone () )
28
28
}
29
29
30
30
// EndOfDecade returns a Carbon instance for end of the decade.
31
31
// 本年代结束时间
32
- func (c Carbon ) EndOfDecade () Carbon {
33
- if c .Error != nil {
32
+ func (c * Carbon ) EndOfDecade () * Carbon {
33
+ if c .IsInvalid () {
34
34
return c
35
35
}
36
- return c . create (c .Year ()/ YearsPerDecade * YearsPerDecade + 9 , 12 , 31 , 23 , 59 , 59 , 999999999 )
36
+ return create (c .Year ()/ YearsPerDecade * YearsPerDecade + 9 , 12 , 31 , 23 , 59 , 59 , 999999999 , c . Timezone () )
37
37
}
38
38
39
39
// StartOfYear returns a Carbon instance for start of the year.
40
40
// 本年开始时间
41
- func (c Carbon ) StartOfYear () Carbon {
42
- if c .Error != nil {
41
+ func (c * Carbon ) StartOfYear () * Carbon {
42
+ if c .IsInvalid () {
43
43
return c
44
44
}
45
- return c . create (c .Year (), 1 , 1 , 0 , 0 , 0 , 0 )
45
+ return create (c .Year (), 1 , 1 , 0 , 0 , 0 , 0 , c . Timezone () )
46
46
}
47
47
48
48
// EndOfYear returns a Carbon instance for end of the year.
49
49
// 本年结束时间
50
- func (c Carbon ) EndOfYear () Carbon {
51
- if c .Error != nil {
50
+ func (c * Carbon ) EndOfYear () * Carbon {
51
+ if c .IsInvalid () {
52
52
return c
53
53
}
54
- return c . create (c .Year (), 12 , 31 , 23 , 59 , 59 , 999999999 )
54
+ return create (c .Year (), 12 , 31 , 23 , 59 , 59 , 999999999 , c . Timezone () )
55
55
}
56
56
57
57
// StartOfQuarter returns a Carbon instance for start of the quarter.
58
58
// 本季度开始时间
59
- func (c Carbon ) StartOfQuarter () Carbon {
60
- if c .Error != nil {
59
+ func (c * Carbon ) StartOfQuarter () * Carbon {
60
+ if c .IsInvalid () {
61
61
return c
62
62
}
63
63
year , quarter , day := c .Year (), c .Quarter (), 1
64
- return c . create (year , 3 * quarter - 2 , day , 0 , 0 , 0 , 0 )
64
+ return create (year , 3 * quarter - 2 , day , 0 , 0 , 0 , 0 , c . Timezone () )
65
65
}
66
66
67
67
// EndOfQuarter returns a Carbon instance for end of the quarter.
68
68
// 本季度结束时间
69
- func (c Carbon ) EndOfQuarter () Carbon {
70
- if c .Error != nil {
69
+ func (c * Carbon ) EndOfQuarter () * Carbon {
70
+ if c .IsInvalid () {
71
71
return c
72
72
}
73
73
year , quarter , day := c .Year (), c .Quarter (), 30
@@ -77,33 +77,33 @@ func (c Carbon) EndOfQuarter() Carbon {
77
77
case 2 , 3 :
78
78
day = 30
79
79
}
80
- return c . create (year , 3 * quarter , day , 23 , 59 , 59 , 999999999 )
80
+ return create (year , 3 * quarter , day , 23 , 59 , 59 , 999999999 , c . Timezone () )
81
81
}
82
82
83
83
// StartOfMonth returns a Carbon instance for start of the month.
84
84
// 本月开始时间
85
- func (c Carbon ) StartOfMonth () Carbon {
86
- if c .Error != nil {
85
+ func (c * Carbon ) StartOfMonth () * Carbon {
86
+ if c .IsInvalid () {
87
87
return c
88
88
}
89
89
year , month , _ := c .Date ()
90
- return c . create (year , month , 1 , 0 , 0 , 0 , 0 )
90
+ return create (year , month , 1 , 0 , 0 , 0 , 0 , c . Timezone () )
91
91
}
92
92
93
93
// EndOfMonth returns a Carbon instance for end of the month.
94
94
// 本月结束时间
95
- func (c Carbon ) EndOfMonth () Carbon {
96
- if c .Error != nil {
95
+ func (c * Carbon ) EndOfMonth () * Carbon {
96
+ if c .IsInvalid () {
97
97
return c
98
98
}
99
99
year , month , _ := c .Date ()
100
- return c . create (year , month + 1 , 0 , 23 , 59 , 59 , 999999999 )
100
+ return create (year , month + 1 , 0 , 23 , 59 , 59 , 999999999 , c . Timezone () )
101
101
}
102
102
103
103
// StartOfWeek returns a Carbon instance for start of the week.
104
104
// 本周开始时间
105
- func (c Carbon ) StartOfWeek () Carbon {
106
- if c .Error != nil {
105
+ func (c * Carbon ) StartOfWeek () * Carbon {
106
+ if c .IsInvalid () {
107
107
return c
108
108
}
109
109
dayOfWeek , weekStartsAt := c .DayOfWeek (), int (c .weekStartsAt )
@@ -112,8 +112,8 @@ func (c Carbon) StartOfWeek() Carbon {
112
112
113
113
// EndOfWeek returns a Carbon instance for end of the week.
114
114
// 本周结束时间
115
- func (c Carbon ) EndOfWeek () Carbon {
116
- if c .Error != nil {
115
+ func (c * Carbon ) EndOfWeek () * Carbon {
116
+ if c .IsInvalid () {
117
117
return c
118
118
}
119
119
dayOfWeek , weekEndsAt := c .DayOfWeek (), int (c .weekStartsAt )+ DaysPerWeek - 1
@@ -122,80 +122,80 @@ func (c Carbon) EndOfWeek() Carbon {
122
122
123
123
// StartOfDay returns a Carbon instance for start of the day.
124
124
// 本日开始时间
125
- func (c Carbon ) StartOfDay () Carbon {
126
- if c .Error != nil {
125
+ func (c * Carbon ) StartOfDay () * Carbon {
126
+ if c .IsInvalid () {
127
127
return c
128
128
}
129
129
year , month , day := c .Date ()
130
- return c . create (year , month , day , 0 , 0 , 0 , 0 )
130
+ return create (year , month , day , 0 , 0 , 0 , 0 )
131
131
}
132
132
133
133
// EndOfDay returns a Carbon instance for end of the day.
134
134
// 本日结束时间
135
- func (c Carbon ) EndOfDay () Carbon {
136
- if c .Error != nil {
135
+ func (c * Carbon ) EndOfDay () * Carbon {
136
+ if c .IsInvalid () {
137
137
return c
138
138
}
139
139
year , month , day := c .Date ()
140
- return c . create (year , month , day , 23 , 59 , 59 , 999999999 )
140
+ return create (year , month , day , 23 , 59 , 59 , 999999999 )
141
141
}
142
142
143
143
// StartOfHour returns a Carbon instance for start of the hour.
144
144
// 小时开始时间
145
- func (c Carbon ) StartOfHour () Carbon {
146
- if c .Error != nil {
145
+ func (c * Carbon ) StartOfHour () * Carbon {
146
+ if c .IsInvalid () {
147
147
return c
148
148
}
149
149
year , month , day := c .Date ()
150
- return c . create (year , month , day , c .Hour (), 0 , 0 , 0 )
150
+ return create (year , month , day , c .Hour (), 0 , 0 , 0 )
151
151
}
152
152
153
153
// EndOfHour returns a Carbon instance for end of the hour.
154
154
// 小时结束时间
155
- func (c Carbon ) EndOfHour () Carbon {
156
- if c .Error != nil {
155
+ func (c * Carbon ) EndOfHour () * Carbon {
156
+ if c .IsInvalid () {
157
157
return c
158
158
}
159
159
year , month , day := c .Date ()
160
- return c . create (year , month , day , c .Hour (), 59 , 59 , 999999999 )
160
+ return create (year , month , day , c .Hour (), 59 , 59 , 999999999 )
161
161
}
162
162
163
163
// StartOfMinute returns a Carbon instance for start of the minute.
164
164
// 分钟开始时间
165
- func (c Carbon ) StartOfMinute () Carbon {
166
- if c .Error != nil {
165
+ func (c * Carbon ) StartOfMinute () * Carbon {
166
+ if c .IsInvalid () {
167
167
return c
168
168
}
169
169
year , month , day , hour , minute , _ := c .DateTime ()
170
- return c . create (year , month , day , hour , minute , 0 , 0 )
170
+ return create (year , month , day , hour , minute , 0 , 0 )
171
171
}
172
172
173
173
// EndOfMinute returns a Carbon instance for end of the minute.
174
174
// 分钟结束时间
175
- func (c Carbon ) EndOfMinute () Carbon {
176
- if c .Error != nil {
175
+ func (c * Carbon ) EndOfMinute () * Carbon {
176
+ if c .IsInvalid () {
177
177
return c
178
178
}
179
179
year , month , day , hour , minute , _ := c .DateTime ()
180
- return c . create (year , month , day , hour , minute , 59 , 999999999 )
180
+ return create (year , month , day , hour , minute , 59 , 999999999 )
181
181
}
182
182
183
183
// StartOfSecond returns a Carbon instance for start of the second.
184
184
// 秒开始时间
185
- func (c Carbon ) StartOfSecond () Carbon {
186
- if c .Error != nil {
185
+ func (c * Carbon ) StartOfSecond () * Carbon {
186
+ if c .IsInvalid () {
187
187
return c
188
188
}
189
189
year , month , day , hour , minute , second := c .DateTime ()
190
- return c . create (year , month , day , hour , minute , second , 0 )
190
+ return create (year , month , day , hour , minute , second , 0 )
191
191
}
192
192
193
193
// EndOfSecond returns a Carbon instance for end of the second.
194
194
// 秒结束时间
195
- func (c Carbon ) EndOfSecond () Carbon {
196
- if c .Error != nil {
195
+ func (c * Carbon ) EndOfSecond () * Carbon {
196
+ if c .IsInvalid () {
197
197
return c
198
198
}
199
199
year , month , day , hour , minute , second := c .DateTime ()
200
- return c . create (year , month , day , hour , minute , second , 999999999 )
200
+ return create (year , month , day , hour , minute , second , 999999999 )
201
201
}
0 commit comments