Get the difference in years

@param Carbon|\DateTimeInterface|string|null $date
@param bool                                  $absolute Get the absolute of the difference

@return int
160825
public function diffInYears($date = null, $absolute = true)
    {
        return (int) $this->diff($this->resolveCarbon($date), $absolute)->format('%r%y');
    }
1121444
final protected function mutateDateTimeAttribute($date, $attribute)
	{
		if (is_numeric($date)) {
			return $this->attributes[$attribute] = Carbon::createFromTimestamp($date);
		}

		return $this->attributes[$attribute] = Carbon::parse($date)->toDateTimeString();
	}
610805
public function diff($datetime, $absolute = false)
    {
        $d1 = clone $this;
        $d2 = $datetime instanceof \DateTime ? new static($datetime->format(DateTime::ISO8601)) : clone $datetime;

        $interval = new DateInterval('PT0.000000S');
        foreach (get_object_vars(parent::diff($datetime)) as $property => $value) {
            $interval->{$property} = $value;
        }
        $interval->s = 0;

        $negative = $d1->getTimestampWithMicroseconds() > $d2->getTimestampWithMicroseconds();
        $diff = abs($d1->getTimestampWithMicroseconds() - $d2->getTimestampWithMicroseconds());

        $seconds = intval($diff);
        $microseconds = round($diff - $seconds, 6) * 1e6;

        $now = new \DateTime('now');
        $start = $now->getTimestamp();

        $operation = $negative ? 'sub' : 'add';
        $now->$operation($interval);

        $end = $now->getTimestamp();
        $antiseconds = abs($end - $start);

        $interval->s = $seconds - $antiseconds;
        $interval->u = $microseconds;
        $interval->invert = $absolute ? false : $negative;

        return $interval;
    }
631500
public function diff($datetime, $absolute = false)
    {
        if ($datetime instanceof DateTime) {
            return $this->dateTime->diff($datetime->toGregorian(), $absolute);
        }

        return $this->dateTime->diff($datetime, $absolute);
    }
312309
public function byYears(int $years): Date
    {
        return $this->yearTo($this->originalDate->year() + $years);
    }
768873
protected function refactorRolledOverDate(Carbon $date, Carbon $original_date)
    {
        return $date
            ->subMonth()
            ->endOfMonth()
            ->setTime($original_date->hour, $original_date->minute, $original_date->second);
    }
346560
public function floatDiffInHours($date = null, $absolute = true)
    {
        return $this->floatDiffInMinutes($date, $absolute) / static::MINUTES_PER_HOUR;
    }
1047966
public function diffInWeekdays($date = null, $absolute = true)
    {
        return $this->diffInDaysFiltered(function (CarbonInterface $date) {
            return $date->isWeekday();
        }, $date, $absolute);
    }
1298559
public function getAge($date = null, $months = false)
    {
        $birthDate = $this->getBirthDay();
        
        if (is_null($date)) {
            $date = new \MUtil_Date();
        }        
        
        if (!($birthDate instanceof \MUtil_Date) || !($date instanceof \MUtil_Date)) {
            return null;
        }
        
        // Now calculate age         
        if ($months) {
            $age  = $date->diffMonths($birthDate);                
            $unit = 'dd';        
        } else {
            $age  = $date->diffYears($birthDate);
            $unit = 'MMdd';
        }
        if ($date->get($unit) < $birthDate->get($unit)) {
            $age--;
        } 

        return $age;
    }
1142746
public static int year(EvaluationContext ctx, Object date) {
        return Conversions.toDateOrDateTime(date, ctx).get(ChronoField.YEAR);
    }
237060
final public static function asSql($date)
    {
        if (!empty($date)) {
            if ($date instanceof \DateTimeInterface) {
                return $date->format('Y-m-d H:i:sO');
            } else {
                return self::asDateTime($date)->format('Y-m-d H:i:sO');
            }
        } else {
            return null;
        }
    }
1164078
public function dateDiff($date, $elaps = "d") {
        $__DAYS_PER_WEEK__       = (7);
        $__DAYS_PER_MONTH__       = (30);
        $__DAYS_PER_YEAR__       = (365);
        $__HOURS_IN_A_DAY__      = (24);
        $__MINUTES_IN_A_DAY__    = (1440);
        $__SECONDS_IN_A_DAY__    = (86400);
        //计算天数差
        $__DAYSELAPS = ($this->parse($date) - $this->date) / $__SECONDS_IN_A_DAY__ ;
        switch ($elaps) {
            case "y"://转换成年
                $__DAYSELAPS =  $__DAYSELAPS / $__DAYS_PER_YEAR__;
                break;
            case "M"://转换成月
                $__DAYSELAPS =  $__DAYSELAPS / $__DAYS_PER_MONTH__;
                break;
            case "w"://转换成星期
                $__DAYSELAPS =  $__DAYSELAPS / $__DAYS_PER_WEEK__;
                break;
            case "h"://转换成小时
                $__DAYSELAPS =  $__DAYSELAPS * $__HOURS_IN_A_DAY__;
                break;
            case "m"://转换成分钟
                $__DAYSELAPS =  $__DAYSELAPS * $__MINUTES_IN_A_DAY__;
                break;
            case "s"://转换成秒
                $__DAYSELAPS =  $__DAYSELAPS * $__SECONDS_IN_A_DAY__;
                break;
        }
        return $__DAYSELAPS;
    }
843481
static public function getDate(string $date, bool $spss = true): ?string {
        $date = trim($date);
        if ($date == '') {
            return null;
        }

        if (is_numeric($date)) {
            return date('Y-m-d', intval($date) - ($spss === true ? self::$spssBase : 0));
        }

        $date = preg_split('/[^0-9]/', $date);
        if (count($date) !== 3) {
            return null;
        }
        for ($i = 0; $i < 3; $i++) {
            if (intval($date[$i]) == 0) {
                return null;
            }
        }

        $month = intval($date[1]);
        if ($date[0] < 32) {
            $year = intval($date[2]);
            $day  = intval($date[0]);
        } else {
            $year = intval($date[0]);
            $day  = intval($date[2]);
        }
        if ($year < 100) {
            $tmp      = date('Y');
            $treshold = $tmp % 100;
            $tmp      = intval($tmp / 100) * 100;
            if ($year > $treshold) {
                $year -= 100;
            }
            $year += $tmp;
        }
        $date = \DateTime::createFromFormat('Y-n-j', $year . '-' . $month . '-' . $day);
        if ($date === false) {
            return null;
        }
        return $date->format('Y-m-d');
    }
1176971
public static int getYearFromData(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		return cal.get(Calendar.YEAR);
	}
800473
public function diffInRealMicroseconds($date = null, $absolute = true)
    {
        /** @var CarbonInterface $date */
        $date = $this->resolveCarbon($date);
        $value = ($date->timestamp - $this->timestamp) * static::MICROSECONDS_PER_SECOND +
            $date->micro - $this->micro;

        return $absolute ? abs($value) : $value;
    }
317948
public static function dataJuliano($date, $format = 'Y-m-d')
    {
        $date = ($date instanceof Carbon) ? $date : Carbon::createFromFormat($format, $date);
        $dateDiff = $date->copy()->day(31)->month(12)->subYear(1)->diffInDays($date);
        return $dateDiff . mb_substr($date->year, -1);
    }
271404
public static Date substractYearsFromDate(final Date date, final int substractYears)
	{
		final Calendar dateOnCalendar = Calendar.getInstance();
		dateOnCalendar.setTime(date);
		dateOnCalendar.add(Calendar.YEAR, substractYears * -1);
		return dateOnCalendar.getTime();
	}