1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-01-17 22:28:46 +01:00

Merge pull request #6370 from rxu/ticket/16962

[ticket/16962] Fix datetime format test
This commit is contained in:
Marc Alexander 2022-02-22 22:38:04 +01:00
commit cc60a63f22
No known key found for this signature in database
GPG Key ID: 50E0D2423696F995

View File

@ -142,6 +142,23 @@ class phpbb_datetime_from_format_test extends phpbb_test_case
);
$timestamp = $user->get_timestamp_from_format('Y-m-d H:i', $timestamp, new DateTimeZone('UTC'));
/* This code is equal to the one from \phpbb\datetime function format()
* If the delta is less than or equal to 1 hour
* and the delta not more than a minute in the past
* and the delta is either greater than -5 seconds
* or timestamp and current time are of the same minute
* format_date() will return relative date format using "... ago" options
*/
$now_ts = strtotime('now');
$delta = $now_ts - $timestamp;
if ($delta <= 3600 && $delta > -60 &&
($delta >= -5 || (($now_ts/ 60) % 60) == (($timestamp / 60) % 60))
)
{
$expected = $user->lang(['datetime', 'AGO'], max(0, (int) floor($delta / 60)));
}
$this->assertEquals($expected, $user->format_date($timestamp, '|Y-m-d| H:i', $forcedate));
}
}