mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
Merge branch 'develop-ascraeus' into develop
* develop-ascraeus: [ticket/13105] Do not display future dates 2+ days ahead as "tomorrow" [ticket/13105] Add a test for relative dates
This commit is contained in:
commit
b703d1e8df
2 changed files with 90 additions and 19 deletions
|
@ -91,25 +91,28 @@ class datetime extends \DateTime
|
||||||
|
|
||||||
$midnight = $midnight->getTimestamp();
|
$midnight = $midnight->getTimestamp();
|
||||||
|
|
||||||
$day = false;
|
if ($timestamp <= $midnight + 2 * 86400)
|
||||||
|
{
|
||||||
|
$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';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($day !== false)
|
if ($day !== false)
|
||||||
{
|
{
|
||||||
// Format using the short formatting and finally swap out the relative token placeholder with the correct value
|
// Format using the short formatting and finally swap out the relative token placeholder with the correct value
|
||||||
return str_replace(self::RELATIVE_WRAPPER . self::RELATIVE_WRAPPER, $this->user->lang['datetime'][$day], strtr(parent::format($format['format_short']), $format['lang']));
|
return str_replace(self::RELATIVE_WRAPPER . self::RELATIVE_WRAPPER, $this->user->lang['datetime'][$day], strtr(parent::format($format['format_short']), $format['lang']));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,6 @@ class phpbb_datetime_from_format_test extends phpbb_test_case
|
||||||
*/
|
*/
|
||||||
public function test_from_format($timezone, $format, $expected)
|
public function test_from_format($timezone, $format, $expected)
|
||||||
{
|
{
|
||||||
global $user;
|
|
||||||
|
|
||||||
$user = new \phpbb\user('\phpbb\datetime');
|
$user = new \phpbb\user('\phpbb\datetime');
|
||||||
$user->timezone = new DateTimeZone($timezone);
|
$user->timezone = new DateTimeZone($timezone);
|
||||||
$user->lang['datetime'] = array(
|
$user->lang['datetime'] = array(
|
||||||
|
@ -55,4 +53,74 @@ class phpbb_datetime_from_format_test extends phpbb_test_case
|
||||||
$timestamp = $user->get_timestamp_from_format($format, $expected, new DateTimeZone($timezone));
|
$timestamp = $user->get_timestamp_from_format($format, $expected, new DateTimeZone($timezone));
|
||||||
$this->assertEquals($expected, $user->format_date($timestamp, $format, true));
|
$this->assertEquals($expected, $user->format_date($timestamp, $format, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function relative_format_date_data()
|
||||||
|
{
|
||||||
|
// If the current time is too close to the testing time,
|
||||||
|
// the relative time will use "x minutes ago" instead of "today ..."
|
||||||
|
// So we use 18:01 in the morning and 06:01 in the afternoon.
|
||||||
|
$testing_time = date('H') <= 12 ? '06:01' : '18:01';
|
||||||
|
|
||||||
|
return array(
|
||||||
|
array(
|
||||||
|
date('Y-m-d', time() + 2 * 86400) . ' ' . $testing_time, false,
|
||||||
|
date('Y-m-d', time() + 2 * 86400) . ' ' . $testing_time,
|
||||||
|
),
|
||||||
|
|
||||||
|
array(
|
||||||
|
date('Y-m-d', time() + 86400) . ' ' . $testing_time, false,
|
||||||
|
'Tomorrow ' . $testing_time,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
date('Y-m-d', time() + 86400) . ' ' . $testing_time, true,
|
||||||
|
date('Y-m-d', time() + 86400) . ' ' . $testing_time,
|
||||||
|
),
|
||||||
|
|
||||||
|
array(
|
||||||
|
date('Y-m-d') . ' ' . $testing_time, false,
|
||||||
|
'Today ' . $testing_time,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
date('Y-m-d') . ' ' . $testing_time, true,
|
||||||
|
date('Y-m-d') . ' ' . $testing_time,
|
||||||
|
),
|
||||||
|
|
||||||
|
array(
|
||||||
|
date('Y-m-d', time() - 86400) . ' ' . $testing_time, false,
|
||||||
|
'Yesterday ' . $testing_time,
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
date('Y-m-d', time() - 86400) . ' ' . $testing_time, true,
|
||||||
|
date('Y-m-d', time() - 86400) . ' ' . $testing_time,
|
||||||
|
),
|
||||||
|
|
||||||
|
array(
|
||||||
|
date('Y-m-d', time() - 2 * 86400) . ' ' . $testing_time, false,
|
||||||
|
date('Y-m-d', time() - 2 * 86400) . ' ' . $testing_time,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider relative_format_date_data()
|
||||||
|
*/
|
||||||
|
public function test_relative_format_date($timestamp, $forcedate, $expected)
|
||||||
|
{
|
||||||
|
$user = new \phpbb\user('\phpbb\datetime');
|
||||||
|
$user->timezone = new DateTimeZone('UTC');
|
||||||
|
$user->lang['datetime'] = array(
|
||||||
|
'TODAY' => 'Today',
|
||||||
|
'TOMORROW' => 'Tomorrow',
|
||||||
|
'YESTERDAY' => 'Yesterday',
|
||||||
|
'AGO' => array(
|
||||||
|
0 => 'less than a minute ago',
|
||||||
|
1 => '%d minute ago',
|
||||||
|
2 => '%d minutes ago',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$timestamp = $user->get_timestamp_from_format('Y-m-d H:i', $timestamp, new DateTimeZone('UTC'));
|
||||||
|
$this->assertEquals($expected, $user->format_date($timestamp, '|Y-m-d| H:i', $forcedate));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue