mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-10 05:18:52 +00:00
[ticket/16823] Make datetime class correctly handle edge cases
PHPBB3-16823
This commit is contained in:
parent
19a5900db5
commit
e1fc0a9059
2 changed files with 17 additions and 4 deletions
|
@ -101,15 +101,15 @@ class datetime extends \DateTime
|
||||||
{
|
{
|
||||||
$day = false;
|
$day = false;
|
||||||
|
|
||||||
if ($timestamp > $midnight + 86400)
|
if ($timestamp >= $midnight + 86400)
|
||||||
{
|
{
|
||||||
$day = 'TOMORROW';
|
$day = 'TOMORROW';
|
||||||
}
|
}
|
||||||
else if ($timestamp > $midnight)
|
else if ($timestamp >= $midnight)
|
||||||
{
|
{
|
||||||
$day = 'TODAY';
|
$day = 'TODAY';
|
||||||
}
|
}
|
||||||
else if ($timestamp > $midnight - 86400)
|
else if ($timestamp >= $midnight - 86400)
|
||||||
{
|
{
|
||||||
$day = 'YESTERDAY';
|
$day = 'YESTERDAY';
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,6 @@ class phpbb_datetime_from_format_test extends phpbb_test_case
|
||||||
$this->assertEquals($expected, $user->format_date($timestamp, $format, true));
|
$this->assertEquals($expected, $user->format_date($timestamp, $format, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function relative_format_date_data()
|
public function relative_format_date_data()
|
||||||
{
|
{
|
||||||
// If the current time is too close to the testing time,
|
// If the current time is too close to the testing time,
|
||||||
|
@ -103,6 +102,20 @@ class phpbb_datetime_from_format_test extends phpbb_test_case
|
||||||
gmdate('Y-m-d', time() - 2 * 86400) . ' ' . $testing_time, false,
|
gmdate('Y-m-d', time() - 2 * 86400) . ' ' . $testing_time, false,
|
||||||
gmdate('Y-m-d', time() - 2 * 86400) . ' ' . $testing_time,
|
gmdate('Y-m-d', time() - 2 * 86400) . ' ' . $testing_time,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// Test edge cases: Yesterday 00:00, Today 00:00, Tomorrow 00:00
|
||||||
|
array(
|
||||||
|
gmdate('Y-m-d', strtotime('yesterday')) . ' 00:00', false,
|
||||||
|
'Yesterday 00:00',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
gmdate('Y-m-d', strtotime('today')) . ' 00:00', false,
|
||||||
|
'Today 00:00',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
gmdate('Y-m-d', strtotime('tomorrow')) . ' 00:00', false,
|
||||||
|
'Tomorrow 00:00',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue