You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All datetime creation methods accept a `timezone` parameter. This parameter accepts an instance of the {b`Tempest\DateTime\Timezone`} enumeration. When not provided, the default timezone, provided by [`date.timezone`](https://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone), will be used.
61
61
@@ -69,6 +69,49 @@ $date = DateTime::now();
69
69
$date->convertToTimezone(Timezone::EUROPE_PARIS);
70
70
```
71
71
72
+
### Computing a duration
73
+
74
+
By calling the `between()` method on a date instance, you may compute the duration between this date and a second one. This method returns a {b`Tempest\DateTime\Duration`} instance.
75
+
76
+
```php
77
+
use Tempest\DateTime\DateTime;
78
+
79
+
$date1 = DateTime::now();
80
+
$date2 = DateTime::parse('2025-09-19 02:00:00');
81
+
$duration = $date1->between($date2);
82
+
```
83
+
84
+
### Comparing dates
85
+
86
+
The {b`Tempest\DateTime\DateTime`} instance provides multiple methods to compare dates against each other, or against the current time. For instance, you may check if a date is before or after another date using the `isBefore()` and `isAfter()` methods, respectively.
87
+
88
+
```php
89
+
// Check if a date is before another date, inclusively
90
+
$date->isBefore($other);
91
+
92
+
// Check if a date is before another date, exclusively
93
+
$date->isBeforeOrAtTheSameTime($other);
94
+
95
+
// Check if a date between two other dates, inclusively
You may format a {b`Tempest\DateTime\DateTime`} instance in a specific format using the `format()` method. This method accepts an optional format string, which is a standard [ICU format](https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax), and an optional locale.
Tempest provides a time-related testing utilities accessible through the `clock` method of the [`IntegrationTest`](https://github.com/tempestphp/tempest-framework/blob/main/src/Tempest/Framework/Testing/IntegrationTest.php) test case.
0 commit comments