mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Better display of normal Time instances with humanize: Today, Tomorrow, and actual time instead of hours.
This commit is contained in:
parent
0eca54f09f
commit
efb0b47647
@ -1119,13 +1119,22 @@ class Time extends DateTime
|
||||
}
|
||||
else if ($days !== 0)
|
||||
{
|
||||
$phrase = lang('Time.days', [abs($days)]);
|
||||
$before = $days < 0;
|
||||
|
||||
// Yesterday/Tommorrow special cases
|
||||
if (abs($days) === 1)
|
||||
{
|
||||
return $before
|
||||
? lang('Time.yesterday')
|
||||
: lang('Time.tomorrow');
|
||||
}
|
||||
|
||||
$phrase = lang('Time.days', [abs($days)]);
|
||||
}
|
||||
else if ($hours !== 0)
|
||||
{
|
||||
$phrase = lang('Time.hours', [abs($hours)]);
|
||||
$before = $hours < 0;
|
||||
// Display the actual time instead of a regular phrase.
|
||||
return $this->format('g:i a');
|
||||
}
|
||||
else if ($minutes !== 0)
|
||||
{
|
||||
@ -1138,8 +1147,8 @@ class Time extends DateTime
|
||||
}
|
||||
|
||||
return $before
|
||||
? $phrase .' '. lang('ago')
|
||||
: lang('Time.inFuture') .' '. $phrase;
|
||||
? lang('Time.ago', [$phrase])
|
||||
: lang('Time.inFuture', [$phrase]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -829,9 +829,9 @@ class TimeTest extends \CIUnitTestCase
|
||||
public function testHumanizeDaysSingle()
|
||||
{
|
||||
Time::setTestNow('March 10, 2017', 'America/Chicago');
|
||||
$time = Time::parse('March 9, 2017', 'America/Chicago');
|
||||
$time = Time::parse('March 8, 2017', 'America/Chicago');
|
||||
|
||||
$this->assertEquals('1 day ago', $time->humanize());
|
||||
$this->assertEquals('2 days ago', $time->humanize());
|
||||
}
|
||||
|
||||
public function testHumanizeDaysPlural()
|
||||
@ -843,35 +843,35 @@ class TimeTest extends \CIUnitTestCase
|
||||
}
|
||||
|
||||
public function testHumanizeDaysForward()
|
||||
{
|
||||
Time::setTestNow('March 10, 2017', 'America/Chicago');
|
||||
$time = Time::parse('March 12, 2017', 'America/Chicago');
|
||||
|
||||
$this->assertEquals('in 2 days', $time->humanize());
|
||||
}
|
||||
|
||||
public function testHumanizeDaysTomorrow()
|
||||
{
|
||||
Time::setTestNow('March 10, 2017', 'America/Chicago');
|
||||
$time = Time::parse('March 11, 2017', 'America/Chicago');
|
||||
|
||||
$this->assertEquals('in 1 day', $time->humanize());
|
||||
$this->assertEquals('Tomorrow', $time->humanize());
|
||||
}
|
||||
|
||||
public function testHumanizeHoursSingle()
|
||||
public function testHumanizeDaysYesterday()
|
||||
{
|
||||
Time::setTestNow('March 10, 2017 12:00', 'America/Chicago');
|
||||
$time = Time::parse('March 10, 2017 11:00', 'America/Chicago');
|
||||
Time::setTestNow('March 10, 2017', 'America/Chicago');
|
||||
$time = Time::parse('March 9, 2017', 'America/Chicago');
|
||||
|
||||
$this->assertEquals('1 hour ago', $time->humanize());
|
||||
$this->assertEquals('Yesterday', $time->humanize());
|
||||
}
|
||||
|
||||
public function testHumanizeHoursPlural()
|
||||
public function testHumanizeHoursAsTime()
|
||||
{
|
||||
Time::setTestNow('March 10, 2017 12:00', 'America/Chicago');
|
||||
$time = Time::parse('March 10, 2017 10:00', 'America/Chicago');
|
||||
$time = Time::parse('March 10, 2017 14:00', 'America/Chicago');
|
||||
|
||||
$this->assertEquals('2 hours ago', $time->humanize());
|
||||
}
|
||||
|
||||
public function testHumanizeHoursForward()
|
||||
{
|
||||
Time::setTestNow('March 10, 2017 12:00', 'America/Chicago');
|
||||
$time = Time::parse('March 10, 2017 13:00', 'America/Chicago');
|
||||
|
||||
$this->assertEquals('in 1 hour', $time->humanize());
|
||||
$this->assertEquals('2:00 pm', $time->humanize());
|
||||
}
|
||||
|
||||
public function testHumanizeMinutesSingle()
|
||||
|
Loading…
x
Reference in New Issue
Block a user