/** * @param int $number * @param string $token * * @return string */ private function formatOrdinal($number, $token) { return (string) call_user_func(MomentLocale::getLocaleString(array('ordinal')), $number, $token); }
/** * @return string */ public function getRelative() { $formatArgs = array(); if ($this->valueInRange($this->getSeconds(), 0, 45)) { $localeKeys = array('relativeTime', 's'); $formatArgs[] = 1; } elseif ($this->valueInRange($this->getSeconds(), 45, 90)) { $localeKeys = array('relativeTime', 'm'); $formatArgs[] = 1; } elseif ($this->valueInRange($this->getSeconds(), 90, 45 * 60)) { $localeKeys = array('relativeTime', 'mm'); $formatArgs[] = $this->roundAbs($this->getMinutes()); } elseif ($this->valueInRange($this->getMinutes(), 45, 90)) { $localeKeys = array('relativeTime', 'h'); $formatArgs[] = 1; } elseif ($this->valueInRange($this->getMinutes(), 90, 22 * 60)) { $localeKeys = array('relativeTime', 'hh'); $formatArgs[] = $this->roundAbs($this->getHours()); } elseif ($this->valueInRange($this->getHours(), 22, 36)) { $localeKeys = array('relativeTime', 'd'); $formatArgs[] = 1; } elseif ($this->valueInRange($this->getHours(), 36, 25 * 24)) { $localeKeys = array('relativeTime', 'dd'); $formatArgs[] = $this->roundAbs($this->getDays()); } elseif ($this->valueInRange($this->getDays(), 25, 45)) { $localeKeys = array('relativeTime', 'M'); $formatArgs[] = 1; } elseif ($this->valueInRange($this->getDays(), 25, 345)) { $localeKeys = array('relativeTime', 'MM'); $formatArgs[] = $this->roundAbs($this->getMonths()); } elseif ($this->valueInRange($this->getDays(), 345, 547)) { $localeKeys = array('relativeTime', 'y'); $formatArgs[] = 1; } else { $localeKeys = array('relativeTime', 'yy'); $formatArgs[] = $this->roundAbs($this->getYears()); } // add to context $formatArgs[] = $this->getDirection(); $formatArgs[] = $this->getMoment(); // render value $time = MomentLocale::renderLocaleString($localeKeys, $formatArgs); // render value result by direction string return MomentLocale::renderLocaleString(array('relativeTime', $this->getDirection()), array($time)); }
/** * @return string */ public function getRelative() { $time = null; if ($this->valueInRange($this->getSeconds(), 0, 45)) { $time = MomentLocale::renderLocaleString(array('relativeTime', 's')); } elseif ($this->valueInRange($this->getSeconds(), 45, 90)) { $time = MomentLocale::renderLocaleString(array('relativeTime', 'm')); } elseif ($this->valueInRange($this->getSeconds(), 90, 45 * 60)) { $time = MomentLocale::renderLocaleString(array('relativeTime', 'mm'), array(round(abs($this->getMinutes())))); } elseif ($this->valueInRange($this->getMinutes(), 45, 90)) { $time = MomentLocale::renderLocaleString(array('relativeTime', 'h')); } elseif ($this->valueInRange($this->getMinutes(), 90, 22 * 60)) { $time = MomentLocale::renderLocaleString(array('relativeTime', 'hh'), array(round(abs($this->getHours())))); } elseif ($this->valueInRange($this->getHours(), 22, 36)) { $time = MomentLocale::renderLocaleString(array('relativeTime', 'd')); } elseif ($this->valueInRange($this->getHours(), 36, 25 * 24)) { $time = MomentLocale::renderLocaleString(array('relativeTime', 'dd'), array(round(abs($this->getDays())))); } elseif ($this->valueInRange($this->getDays(), 25, 45)) { $time = MomentLocale::renderLocaleString(array('relativeTime', 'M')); } elseif ($this->valueInRange($this->getDays(), 25, 345)) { $time = MomentLocale::renderLocaleString(array('relativeTime', 'MM'), array(round(abs($this->getMonths())))); } elseif ($this->valueInRange($this->getDays(), 345, 547)) { $time = MomentLocale::renderLocaleString(array('relativeTime', 'y')); } elseif ($this->getDays() > 547) { $time = MomentLocale::renderLocaleString(array('relativeTime', 'yy'), array(round(abs($this->getYears())))); } $baseString = MomentLocale::getLocaleString(array('relativeTime', $this->getDirection())); return vsprintf($baseString, array($time)); }