public function relativeDate(\DateTimeInterface $date, \DateTimeInterface $baseDate = null, array $options = []) { $options = $this->optionsResolver->resolve($options); if (!isset($this->calculators[$options['calculator']])) { throw new \InvalidArgumentException(sprintf('Undefined date diff calculator "%s"', $options['calculator'])); } $calculator = $this->calculators[$options['calculator']]; $this->formatter->setDateFormat($options['date_format']); return $this->formatter->format($calculator->compute($date, $baseDate)); }
/** * @dataProvider customPlaceholdersTestCases */ public function testCustomPlaceholders(DateDiffResult $result) { $translator = $this->getMockForAbstractClass(TranslatorInterface::class); $formatter = new TranslatorFormatter($translator); $formatter->registerCustomPlaceholder(['yesterday', 'tomorrow'], '%at%', function (DateDiffResult $result) { return $result->getRequest()->getDate()->format('H:i'); }); $translator->expects($this->once())->method('transChoice')->with($result->getKey(), $this->isNull(), ['%count%' => $result->getValue(), '%at%' => $result->getRequest()->getDate()->format('H:i')]); $formatter->format($result); }
/** * @dataProvider translationCases */ public function testTranslation(DateDiffResult $dateDiffResult, $expected) { $this->assertSame($expected, $this->formatter->format($dateDiffResult)); }