예제 #1
0
 /**
  * @test
  */
 public function getCurrentDateTimeReturnsACurrentDateAndTime()
 {
     $now = new \TYPO3\Flow\Utility\Now();
     $context = $this->contextFactory->create(array());
     $currentTime = $context->getCurrentDateTime();
     $this->assertInstanceOf('\\DateTime', $currentTime);
     $this->assertEquals($now->getTimestamp(), $currentTime->getTimestamp(), 1);
 }
 /**
  * Renders a DateTime formatted relative to the current date.
  * Shows the time if the date is the current date.
  * Shows the month and date if the date is the current year.
  * Shows the year/month/date if the date is not the current year.
  *
  * @param \DateTime $date
  * @return string an <img...> html tag
  * @throws \InvalidArgumentException
  */
 public function render(\DateTime $date = null)
 {
     if ($date === null) {
         $date = $this->renderChildren();
     }
     if (!$date instanceof \DateTime) {
         throw new \InvalidArgumentException('No valid date given,', 1424647058);
     }
     // More than 11 months ago
     $now = new \TYPO3\Flow\Utility\Now();
     if ($date < $now->modify('-11 months')) {
         return $date->format('Y M j');
     }
     // Same day of same year
     $now = new \TYPO3\Flow\Utility\Now();
     if ($date->format('Y z') === $now->format('Y z')) {
         return $date->format('H:i');
     }
     return $date->format('M j');
 }