File tree 4 files changed +114
-0
lines changed
4 files changed +114
-0
lines changed Original file line number Diff line number Diff line change @@ -2889,6 +2889,30 @@ public static function isModifiableUnit($unit): bool;
2889
2889
*/
2890
2890
public static function isMutable (): bool ;
2891
2891
2892
+ /**
2893
+ * Determines if the instance is now or in the future, ie. greater (after) than or equal to now.
2894
+ *
2895
+ * @example
2896
+ * ```
2897
+ * Carbon::now()->isNowOrFuture(); // true
2898
+ * Carbon::now()->addHours(5)->isNowOrFuture(); // true
2899
+ * Carbon::now()->subHours(5)->isNowOrFuture(); // false
2900
+ * ```
2901
+ */
2902
+ public function isNowOrFuture (): bool ;
2903
+
2904
+ /**
2905
+ * Determines if the instance is now or in the past, ie. less (before) than or equal to now.
2906
+ *
2907
+ * @example
2908
+ * ```
2909
+ * Carbon::now()->isNowOrPast(); // true
2910
+ * Carbon::now()->subHours(5)->isNowOrPast(); // true
2911
+ * Carbon::now()->addHours(5)->isNowOrPast(); // false
2912
+ * ```
2913
+ */
2914
+ public function isNowOrPast (): bool ;
2915
+
2892
2916
/**
2893
2917
* Determines if the instance is in the past, ie. less (before) than now.
2894
2918
*
Original file line number Diff line number Diff line change @@ -460,6 +460,36 @@ public function isPast(): bool
460
460
return $ this ->lessThan ($ this ->nowWithSameTz ());
461
461
}
462
462
463
+ /**
464
+ * Determines if the instance is now or in the future, ie. greater (after) than or equal to now.
465
+ *
466
+ * @example
467
+ * ```
468
+ * Carbon::now()->isNowOrFuture(); // true
469
+ * Carbon::now()->addHours(5)->isNowOrFuture(); // true
470
+ * Carbon::now()->subHours(5)->isNowOrFuture(); // false
471
+ * ```
472
+ */
473
+ public function isNowOrFuture (): bool
474
+ {
475
+ return $ this ->greaterThanOrEqualTo ($ this ->nowWithSameTz ());
476
+ }
477
+
478
+ /**
479
+ * Determines if the instance is now or in the past, ie. less (before) than or equal to now.
480
+ *
481
+ * @example
482
+ * ```
483
+ * Carbon::now()->isNowOrPast(); // true
484
+ * Carbon::now()->subHours(5)->isNowOrPast(); // true
485
+ * Carbon::now()->addHours(5)->isNowOrPast(); // false
486
+ * ```
487
+ */
488
+ public function isNowOrPast (): bool
489
+ {
490
+ return $ this ->lessThanOrEqualTo ($ this ->nowWithSameTz ());
491
+ }
492
+
463
493
/**
464
494
* Determines if the instance is a leap year.
465
495
*
Original file line number Diff line number Diff line change @@ -240,6 +240,36 @@ public function testNowIsPastFalse()
240
240
$ this ->assertFalse (Carbon::now ()->isPast ());
241
241
}
242
242
243
+ public function testIsNowOrFutureTrue ()
244
+ {
245
+ $ this ->assertTrue (Carbon::now ()->addSecond ()->isNowOrFuture ());
246
+ }
247
+
248
+ public function testIsNowOrFutureFalse ()
249
+ {
250
+ $ this ->assertFalse (Carbon::now ()->subSecond ()->isNowOrFuture ());
251
+ }
252
+
253
+ public function testNowIsNowOrFutureTrue ()
254
+ {
255
+ $ this ->assertTrue (Carbon::now ()->isNowOrFuture ());
256
+ }
257
+
258
+ public function testIsNowOrPastTrue ()
259
+ {
260
+ $ this ->assertTrue (Carbon::now ()->subSecond ()->isNowOrPast ());
261
+ }
262
+
263
+ public function testIsNowOrPastFalse ()
264
+ {
265
+ $ this ->assertFalse (Carbon::now ()->addSecond ()->isNowOrPast ());
266
+ }
267
+
268
+ public function testNowIsNowOrPastTrue ()
269
+ {
270
+ $ this ->assertTrue (Carbon::now ()->isNowOrPast ());
271
+ }
272
+
243
273
public function testIsLeapYearTrue ()
244
274
{
245
275
$ this ->assertTrue (Carbon::createFromDate (2016 , 1 , 1 )->isLeapYear ());
Original file line number Diff line number Diff line change @@ -237,6 +237,36 @@ public function testNowIsPastFalse()
237
237
$ this ->assertFalse (Carbon::now ()->isPast ());
238
238
}
239
239
240
+ public function testIsNowOrFutureTrue ()
241
+ {
242
+ $ this ->assertTrue (Carbon::now ()->addSecond ()->isNowOrFuture ());
243
+ }
244
+
245
+ public function testIsNowOrFutureFalse ()
246
+ {
247
+ $ this ->assertFalse (Carbon::now ()->subSecond ()->isNowOrFuture ());
248
+ }
249
+
250
+ public function testNowIsNowOrFutureTrue ()
251
+ {
252
+ $ this ->assertTrue (Carbon::now ()->isNowOrFuture ());
253
+ }
254
+
255
+ public function testIsNowOrPastTrue ()
256
+ {
257
+ $ this ->assertTrue (Carbon::now ()->subSecond ()->isNowOrPast ());
258
+ }
259
+
260
+ public function testIsNowOrPastFalse ()
261
+ {
262
+ $ this ->assertFalse (Carbon::now ()->addSecond ()->isNowOrPast ());
263
+ }
264
+
265
+ public function testNowIsNowOrPastTrue ()
266
+ {
267
+ $ this ->assertTrue (Carbon::now ()->isNowOrPast ());
268
+ }
269
+
240
270
public function testIsLeapYearTrue ()
241
271
{
242
272
$ this ->assertTrue (Carbon::createFromDate (2016 , 1 , 1 )->isLeapYear ());
You can’t perform that action at this time.
0 commit comments