fieldDifference example


    public function humanize()
    {
        $now  = IntlCalendar::fromDateTime(self::now($this->timezone));
        $time = $this->getCalendar()->getTime();

        $years   = $now->fieldDifference($time, IntlCalendar::FIELD_YEAR);
        $months  = $now->fieldDifference($time, IntlCalendar::FIELD_MONTH);
        $days    = $now->fieldDifference($time, IntlCalendar::FIELD_DAY_OF_YEAR);
        $hours   = $now->fieldDifference($time, IntlCalendar::FIELD_HOUR_OF_DAY);
        $minutes = $now->fieldDifference($time, IntlCalendar::FIELD_MINUTE);

        $phrase = null;

        if ($years !== 0) {
            $phrase = lang('Time.years', [abs($years)]);
            $before = $years < 0;
        } elseif ($months !== 0) {
            

    public function getYears(bool $raw = false)
    {
        if ($raw) {
            return $this->difference / YEAR;
        }

        $time = clone $this->currentTime;

        return $time->fieldDifference($this->testTime, IntlCalendar::FIELD_YEAR);
    }

    /** * Returns the number of months difference between the two dates. * * @return float|int */
    public function getMonths(bool $raw = false)
    {
        if ($raw) {
            return $this->difference / MONTH;
        }
Home | Imprint | This part of the site doesn't use cookies.