Skip to content

Commit 46c8651

Browse files
committed
document time helpers
1 parent 36bb96d commit 46c8651

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

helpers.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
- [Available Methods](#available-methods)
55
- [Other Utilities](#other-utilities)
66
- [Benchmarking](#benchmarking)
7-
- [Dates](#dates)
7+
- [Dates and Time](#dates)
88
- [Deferred Functions](#deferred-functions)
99
- [Lottery](#lottery)
1010
- [Pipeline](#pipeline)
@@ -3194,7 +3194,7 @@ Sometimes, you may want to benchmark the execution of a callback while still obt
31943194
```
31953195

31963196
<a name="dates"></a>
3197-
### Dates
3197+
### Dates and Time
31983198

31993199
Laravel includes [Carbon](https://carbon.nesbot.com/docs/), a powerful date and time manipulation library. To create a new `Carbon` instance, you may invoke the `now` function. This function is globally available within your Laravel application:
32003200

@@ -3210,8 +3210,33 @@ use Illuminate\Support\Carbon;
32103210
$now = Carbon::now();
32113211
```
32123212

3213+
Laravel also augments `Carbon` instances with `plus` and `minus` methods, allowing easy manipulation of the instance's date and time:
3214+
3215+
```php
3216+
return now()->plus(minutes: 5);
3217+
return now()->plus(hours: 8);
3218+
return now()->plus(weeks: 4);
3219+
3220+
return now()->minus(minutes: 5);
3221+
return now()->minus(hours: 8);
3222+
return now()->minus(weeks: 4);
3223+
```
3224+
32133225
For a thorough discussion of Carbon and its features, please consult the [official Carbon documentation](https://carbon.nesbot.com/docs/).
32143226

3227+
<a name="interval-functions"></a>
3228+
#### Interval Functions
3229+
3230+
Laravel also offers `seconds`, `minutes`, `hours`, `days`, and `years` functions that return `CarbonInterval` instances, which extend PHP's [DateInterval](https://www.php.net/manual/en/class.dateinterval.php) class. These functions may be used anywhere that Laravel accepts a `DateInterval` instance:
3231+
3232+
```php
3233+
use Illuminate\Support\Facades\Cache;
3234+
3235+
use function Illuminate\Support\{minutes};
3236+
3237+
Cache::put('metrics', $metrics, minutes(10));
3238+
```
3239+
32153240
<a name="deferred-functions"></a>
32163241
### Deferred Functions
32173242

0 commit comments

Comments
 (0)