Exemplo n.º 1
0
 /**
  * @param PreciseDifference $difference
  * @param string            $locale
  *
  * @return string
  */
 public function formatDifference(PreciseDifference $difference, $locale = 'en')
 {
     $diff = array();
     foreach ($difference->getCompoundResults() as $result) {
         $diff[] = $this->translator->transChoice('compound.' . $result->getUnit()->getName(), $result->getQuantity(), array('%count%' => $result->getQuantity()), 'difference', $locale);
     }
     return $this->translator->trans('compound.' . ($difference->isPast() ? 'past' : 'future'), array('%value%' => implode(', ', $diff)), 'difference', $locale);
 }
Exemplo n.º 2
0
 /**
  * @param PreciseDifference $difference
  * @param string $locale
  * @return string
  */
 public function formatDifference(PreciseDifference $difference, $locale = 'en')
 {
     $diff = array();
     foreach ($difference->getCompoundResults() as $result) {
         $diff[] = $this->translator->transChoice("compound." . $result->getUnit()->getName(), $result->getQuantity(), array('%count%' => $result->getQuantity()), 'difference', $locale);
     }
     $suffix = $difference->isPast() ? 'compound.ago' : 'compound.from_now';
     return join(", ", $diff) . ' ' . $this->translator->trans($suffix, array(), 'difference', $locale);
 }
 function it_format_compound_datetime_diff_for_specific_locale(PreciseDifference $diff, CompoundResult $dayResult, CompoundResult $hourResult)
 {
     $dayResult->getUnit()->willReturn(new Day());
     $dayResult->getQuantity()->willReturn(10);
     $hourResult->getUnit()->willReturn(new Hour());
     $hourResult->getQuantity()->willReturn(5);
     $diff->getCompoundResults()->willReturn(array($dayResult, $hourResult));
     $diff->isPast()->willReturn(false);
     $this->formatDifference($diff, 'ru')->shouldReturn('через 10 дней, 5 часов');
 }