@@ -174,35 +174,39 @@ public function getStartTime(): ?Carbon
174174 /**
175175 * With start time.
176176 */
177- public function withStartTime (DateTime $ timestamp ): self
177+ public function withStartTime (? DateTime $ timestamp ): self
178178 {
179- Arr::set ($ this ->options , 'starts_at ' , Carbon::instance ($ timestamp ));
179+ if ($ timestamp === null ) {
180+ Arr::forget ($ this ->options , 'starts_at ' );
181+ } else {
182+ Arr::set ($ this ->options , 'starts_at ' , Carbon::instance ($ timestamp ));
183+ }
180184
181185 return $ this ;
182186 }
183187
184188 /**
185189 * With start time in the given interval.
186190 */
187- public function withStartTimeIn (DateInterval $ interval ): self
191+ public function withStartTimeIn (? DateInterval $ interval ): self
188192 {
189- return $ this ->withStartTime (Carbon::now ()->add ($ interval ));
193+ return $ this ->withStartTime ($ interval ? Carbon::now ()->add ($ interval ) : null );
190194 }
191195
192196 /**
193197 * With start date - time component is set to 00:00:00.000000.
194198 */
195- public function withStartDate (DateTime $ timestamp ): self
199+ public function withStartDate (? DateTime $ timestamp ): self
196200 {
197- return $ this ->withStartTime (Carbon::instance ($ timestamp )->startOfDay ());
201+ return $ this ->withStartTime ($ timestamp ? Carbon::instance ($ timestamp )->startOfDay () : null );
198202 }
199203
200204 /**
201205 * With start date in the given interval - time component is set to 00:00:00.000000.
202206 */
203- public function withStartDateIn (DateInterval $ interval ): self
207+ public function withStartDateIn (? DateInterval $ interval ): self
204208 {
205- return $ this ->withStartTime (Carbon::now ()->add ($ interval )->startOfDay ());
209+ return $ this ->withStartTime ($ interval ? Carbon::now ()->add ($ interval )->startOfDay () : null );
206210 }
207211
208212 /**
@@ -216,35 +220,39 @@ public function getExpireTime(): ?Carbon
216220 /**
217221 * With expire time.
218222 */
219- public function withExpireTime (DateTime $ timestamp ): self
223+ public function withExpireTime (? DateTime $ timestamp ): self
220224 {
221- Arr::set ($ this ->options , 'expires_at ' , Carbon::instance ($ timestamp ));
225+ if ($ timestamp === null ) {
226+ Arr::forget ($ this ->options , 'expires_at ' );
227+ } else {
228+ Arr::set ($ this ->options , 'expires_at ' , Carbon::instance ($ timestamp ));
229+ }
222230
223231 return $ this ;
224232 }
225233
226234 /**
227235 * With expire time in the given interval.
228236 */
229- public function withExpireTimeIn (DateInterval $ interval ): self
237+ public function withExpireTimeIn (? DateInterval $ interval ): self
230238 {
231- return $ this ->withExpireTime (Carbon::now ()->add ($ interval ));
239+ return $ this ->withExpireTime ($ interval ? Carbon::now ()->add ($ interval ) : null );
232240 }
233241
234242 /**
235243 * With expire date - time component is set to 23:59:59.999999.
236244 */
237- public function withExpireDate (DateTime $ timestamp ): self
245+ public function withExpireDate (? DateTime $ timestamp ): self
238246 {
239- return $ this ->withExpireTime (Carbon::instance ($ timestamp )->endOfDay ());
247+ return $ this ->withExpireTime ($ timestamp ? Carbon::instance ($ timestamp )->endOfDay () : null );
240248 }
241249
242250 /**
243251 * With expire date in the given interval - time component is set to 23:59:59.999999.
244252 */
245- public function withExpireDateIn (DateInterval $ interval ): self
253+ public function withExpireDateIn (? DateInterval $ interval ): self
246254 {
247- return $ this ->withExpireTime (Carbon::now ()->add ($ interval )->endOfDay ());
255+ return $ this ->withExpireTime ($ interval ? Carbon::now ()->add ($ interval )->endOfDay () : null );
248256 }
249257
250258 /**
0 commit comments