/** * Returns date/time like Today, 10:00 AM * * @param $datetime * @param string $timezone * @param string $fromFormat */ public function toText($datetime, $timezone = 'local', $fromFormat = 'Y-m-d H:i:s') { if (empty($datetime)) { return ''; } $this->helper->setDateTime($datetime, $fromFormat, $timezone); $textDate = $this->helper->getTextDate(); $dt = $this->helper->getLocalDateTime(); if ($textDate) { return $this->translator->trans('mautic.core.date.' . $textDate, array('%time%' => $dt->format("g:i a"))); } else { $interval = $this->helper->getDiff('now', null, true); return $this->translator->trans('mautic.core.date.ago', array('%days%' => $interval->days)); } }
/** * Returns date/time like Today, 10:00 AM * * @param $datetime * @param string $timezone * @param string $fromFormat * @param bool $forceDateForNonText If true, return as full date/time rather than "29 days ago" * * @return string */ public function toText($datetime, $timezone = 'local', $fromFormat = 'Y-m-d H:i:s', $forceDateForNonText = false) { if (empty($datetime)) { return ''; } $this->helper->setDateTime($datetime, $fromFormat, $timezone); $textDate = $this->helper->getTextDate(); $dt = $this->helper->getLocalDateTime(); if ($textDate) { return $this->translator->trans('mautic.core.date.' . $textDate, array('%time%' => $dt->format("g:i a"))); } else { $interval = $this->helper->getDiff('now', null, true); if ($interval->invert && !$forceDateForNonText) { // In the past return $this->translator->trans('mautic.core.date.ago', array('%days%' => $interval->days)); } else { // In the future return $this->toFullConcat($datetime, $timezone, $fromFormat); } } }