relLengthOfTime() public static method

Time relative to NOW in human readable format - absolute (negative as well as positive) TODO: make "now" adjustable
public static relLengthOfTime ( mixed $date, string | null $format = null, array $options = [] ) : string
$date mixed
$format string | null Format
$options array Options - default, separator - boolean zero: if false: 0 days 5 hours => 5 hours etc. - verbose/past/future: string with %s or boolean true/false
return string
Beispiel #1
0
 /**
  * TimeTest::testRelLengthOfTime()
  *
  * @return void
  */
 public function testRelLengthOfTime()
 {
     $ret = $this->Time->relLengthOfTime('1990-11-20');
     //pr($ret);
     $ret = $this->Time->relLengthOfTime('2012-11-20');
     //pr($ret);
     $res = $this->Time->relLengthOfTime(date(FORMAT_DB_DATETIME, time() - 3600));
     //pr($res);
     $this->assertTrue(!empty($res));
     $res = $this->Time->relLengthOfTime(date(FORMAT_DB_DATETIME, time() - 4 * DAY - 5 * HOUR), null, ['plural' => 'n']);
     //pr($res);
     //$this->assertEquals($res, 'Vor 4 Tagen, 5 '.__d('tools', 'Hours'));
     $this->assertEquals(__d('tools', '{0} ago', '4 ' . __d('tools', 'Days') . ', ' . '5 ' . __d('tools', 'Hours')), $res);
     $res = $this->Time->relLengthOfTime(date(FORMAT_DB_DATETIME, time() + 4 * DAY + 5 * HOUR), null, ['plural' => 'n']);
     //pr($res);
     $this->assertEquals(__d('tools', 'In {0}', '4 ' . __d('tools', 'Days') . ', ' . '5 ' . __d('tools', 'Hours')), $res);
     $res = $this->Time->relLengthOfTime(date(FORMAT_DB_DATETIME, time()), null, ['plural' => 'n']);
     //pr($res);
     $this->assertEquals($res, __d('tools', 'justNow'));
 }