Skip to content

Commit f3292e7

Browse files
committed
DateTime: fixed parsing 'ago' modifier [Closes #327]
1 parent e7e6b88 commit f3292e7

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Utils/DateTime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ private function apply(string $datetime, $timezone = null, bool $ctr = false): v
158158
{
159159
$relPart = '';
160160
$absPart = preg_replace_callback(
161-
'/[+-]?\s*\d+\s+((microsecond|millisecond|[mµu]sec)s?|[mµ]s|sec(ond)?s?|min(ute)?s?|hours?)\b/iu',
161+
'/[+-]?\s*\d+\s+((microsecond|millisecond|[mµu]sec)s?|[mµ]s|sec(ond)?s?|min(ute)?s?|hours?)(\s+ago)?\b/iu',
162162
function ($m) use (&$relPart) {
163163
$relPart .= $m[0] . ' ';
164164
return '';

tests/Utils/DateTime.modify.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ test('Complex and varied format strings', function () {
157157
// 'first day of may' -> 2024-05-01 00:00 | 'noon' -> 2024-05-01 12:00
158158
$dt->modify('first day of may 2024 noon');
159159
Assert::same('2024-05-01 12:00:00 CEST (+02:00)', $dt->format('Y-m-d H:i:s T (P)'), 'Chained textual modifiers');
160+
161+
// ago
162+
$dt = new DateTime('2024-03-10 10:00:00'); // CET
163+
$dt->modify('12 minutes ago');
164+
Assert::same('2024-03-10 09:48:00 CET (+01:00)', $dt->format('Y-m-d H:i:s T (P)'), 'Ago modifier');
160165
});
161166

162167

0 commit comments

Comments
 (0)