Exemplo n.º 1
0
 public function testConvertsDatesToImmutableVersion()
 {
     $baseDate = \DateTime::createFromFormat('U', 12345);
     $date = \DateTime::createFromFormat('U', 12345678);
     $request = new DateDiffRequest($date, $baseDate);
     $this->assertInstanceOf(\DateTimeImmutable::class, $request->getBaseDate());
     $this->assertSame($baseDate->getTimestamp(), $request->getBaseDate()->getTimestamp());
     $this->assertEquals($baseDate->getTimezone(), $request->getBaseDate()->getTimezone());
     $this->assertInstanceOf(\DateTimeImmutable::class, $request->getDate());
     $this->assertSame($date->getTimestamp(), $request->getDate()->getTimestamp());
     $this->assertEquals($date->getTimezone(), $request->getDate()->getTimezone());
 }
Exemplo n.º 2
0
 public function isApplicable(DateDiffRequest $diffRequest)
 {
     return !$diffRequest->getInterval()->invert && $diffRequest->getInterval()->y >= 1;
 }
Exemplo n.º 3
0
 /**
  * Returns "years ago" result with absolute diff in calendar years
  *
  * @param DateDiffRequest $request
  * @return DateDiffResult
  */
 public static function calculateYearsAgo(DateDiffRequest $request)
 {
     return new DateDiffResult($request, self::YEARS_AGO, $request->getInterval()->y);
 }
Exemplo n.º 4
0
 public function isApplicable(DateDiffRequest $diffRequest)
 {
     $tomorrowDate = $diffRequest->getBaseDate()->add(new \DateInterval('P1D'));
     return $tomorrowDate->format('Ymd') === $diffRequest->getDate()->format('Ymd');
 }
Exemplo n.º 5
0
 public function isApplicable(DateDiffRequest $diffRequest)
 {
     $i = $diffRequest->getInterval();
     return !$i->invert && $i->d >= 7;
 }
Exemplo n.º 6
0
 public function isApplicable(DateDiffRequest $diffRequest)
 {
     $yesterdayDate = $diffRequest->getBaseDate()->sub(new \DateInterval('P1D'));
     return $yesterdayDate->format('Ymd') === $diffRequest->getDate()->format('Ymd');
 }
Exemplo n.º 7
0
 public function isApplicable(DateDiffRequest $diffRequest)
 {
     return $diffRequest->getCalendarMonths() < 0;
 }