コード例 #1
0
 /**
  * @covers \php_rutils\Dt::distanceOfTimeInWords
  */
 public function testFromTimeFuture()
 {
     $fromTime = new \DateTime();
     $fromTime->add(new \DateInterval('P56Y'));
     $toTime = new \DateTime();
     $toTime->sub(new \DateInterval('P11Y3M12DT4H2M'));
     $this->assertEquals("67 лет, 3 месяца, 12 дней, 4 часа, 2 минуты назад", $this->_object->distanceOfTimeInWords($toTime, $fromTime, RUtils::ACCURACY_MINUTE));
 }
コード例 #2
0
ファイル: DtTest.php プロジェクト: ragenoir/php_rutils
 /**
  * @covers \php_rutils\Dt::getAge
  */
 public function testGetAgeIncorrectType()
 {
     $birthDate = new \DateTimeZone('UTC');
     try {
         $this->_object->getAge($birthDate);
         $this->fail('Incorrect date passed');
     } catch (\InvalidArgumentException $e) {
         $this->assertEquals('Incorrect date/time type', $e->getMessage());
     }
 }
コード例 #3
0
ファイル: dt.php プロジェクト: ragenoir/php_rutils
$toTime = new \DateTime('05-06-1945');
//Unix timestamp and string also available
echo RUtils::dt()->distanceOfTimeInWords($toTime), PHP_EOL;
//Result: 68 лет назад
$toTime = strtotime('05-06-1945');
$fromTime = null;
//now
$accuracy = RUtils::ACCURACY_MINUTE;
//years, months, days, hours, minutes
echo RUtils::dt()->distanceOfTimeInWords($toTime, $fromTime, $accuracy), PHP_EOL;
//Result: 68 лет, 4 месяца, 21 день, 19 часов, 12 минут назад
//Time distance from fixed date in past to date in future
$fromTime = '1988-01-01 11:40';
$toTime = '2088-01-01 12:35';
$accuracy = RUtils::ACCURACY_MINUTE;
//years, months, days, hours, minutes
echo RUtils::dt()->distanceOfTimeInWords($toTime, $fromTime, $accuracy), PHP_EOL;
//Result: через 100 лет, 55 минут
//Get age by date
$birthDate = strtotime('today - 25 years');
echo RUtils::dt()->getAge($birthDate), PHP_EOL;
//Result: 25
//Custom prefix in
Dt::$PREFIX_IN = 'опосля';
$fromTime = '1988-01-01 11:40';
$toTime = '2088-01-01 12:35';
$accuracy = RUtils::ACCURACY_MINUTE;
//years, months, days, hours, minutes
echo RUtils::dt()->distanceOfTimeInWords($toTime, $fromTime, $accuracy), PHP_EOL;
//Result: опосля 100 лет, 55 минут
require '_end.php';