1 Year is defined as 365 days and 1 Month is defined as 30 days
@param DateInterval $dateInterval
@return float|int turn to seconds
182298
public static function turnDateIntervalToSeconds(DateInterval $dateInterval)
    {
        return $dateInterval->y * 365 * 24 * 3600
            + $dateInterval->m * 30 * 24 * 3600
            + $dateInterval->d * 24 * 3600
            + $dateInterval->h * 3600
            + $dateInterval->i * 60
            + $dateInterval->s;
    }
776728
public function getDayOfYear() : int
    {
        return Month::of($this->month)->getFirstDayOfYear($this->isLeapYear()) + $this->day - 1;
    }
642713
public function plusMonths(int $months) : YearMonth
    {
        if ($months === 0) {
            return $this;
        }

        $month = $this->month + $months - 1;

        $yearDiff = Math::floorDiv($month, 12);
        $month = Math::floorMod($month, 12) + 1;

        $year = $this->year + $yearDiff;

        return new YearMonth($year, $month);
    }
1166143
private function formatNormal(\DateInterval $diff)
    {
        $str = '';
        $first = null;
        $second = null;
        $val = 0;

        if ($diff->y > 0) {
            $str = "year";
            $val = $diff->y;
        } else if ($diff->m > 0) {
            $str = "month";
            $val = $diff->m;
        } else if ($diff->d > 0) {
            $str = "day";
            $first = array('after' => "tomorrow", 'before' => "yesterday");
            $val = $diff->d;
        } else if ($diff->h > 0) {
            $str = "hour";
            $val = $diff->h;
        } else if ($diff->i == 30) {
            var_dump($diff->invert);
            return $diff->invert ? $this->translator->trans("next half hour") : $this->translator->trans("half hour ago");
        } else if ($diff->i > 0) {
            $str = "minute";
            $val = $diff->i;
        } else if ($diff->s > 0) {
            $str = "second";
            $val = $diff->s;
        }

        $id = "%" . $str . "s%";

        if ($diff->invert) {
            return $this->translator->transChoice(
                ($first && isset($first['after']) ? $first['after'] : "next " . $str) . "|" .
                ($second && isset($second['after']) ? $second['after'] : "next " . $id . " " . $str . "s"), $val, array(
                $id => $val
            ));
        } else {
            return $this->translator->transChoice(
                ($first && isset($first['before']) ? $first['before'] : ($str == "hour" ? 'an' : 'a') . ' ' . $str . ' ago') . "|" .
                ($second && isset($second['before']) ? $second['before'] : $id . " " . $str . "s ago"), $val, array(
                $id => $val
            ));
        }
    }
62485
private function getIntervalUnits(\DateTime $date1, \DateTime $date2, string $intervalFormat)
    {
        $result = 0;
        try {
            $interval = new \DateInterval($intervalFormat);
            $periods  = new \DatePeriod($date1, $interval, $date2);

            $result = max(0, iterator_count($periods) - 1);
        } catch (\Exception $e) {
        }

        return $result;
    }
1189204
public static function getDaysInMonth($month, $year)
    {
        if ($year == 1582 && $month == 10) {
            return 21;  // October 1582 only had 1st-4th and 15th-31st
        }

        if ($month == 2) {
            if (self::isLeapYear($year)) {
                return 29;
            } else {
                return 28;
            }
        } elseif ($month == 4 or $month == 6 or $month == 9 or $month == 11) {
            return 30;
        } else {
            return 31;
        }
    }
272991
public function add(\DateInterval $interval)
    {
        $this->startDate->add($interval);
        $this->endDate->add($interval);

        return $this;
    }
1332688
function (year) {
			var daysCount = 0;
			for (var i = 1; i <= 12; i++) {
				daysCount += this.daysInMonth(year, i);
			}
			return daysCount;
		}
209814
public static function intervalToTime(DateInterval $interval)
    {
        $time = null;

        if (!is_null($interval)) {
            $format = property_exists(get_class($interval), 'u') ? '%H:%I:%S.%U' : '%H:%I:%S';
            $time = $interval->format($format);
        }

        return $time;
    }
515165
public function add(DateInterval $interval)
	{
		$years   = $this->y + $interval->y;
		$months  = $this->m + $interval->m;
		$days    = $this->d + $interval->d;
		$hours   = $this->h + $interval->h;
		$minutes = $this->i + $interval->i;
		$seconds = $this->s + $interval->s;

		$spec = sprintf('P%sY%sM%sDT%sH%sM%sS', $years, $months, $days, $hours, $minutes, $seconds);

		return new DateInterval($spec);
	}
1302803
protected function calculateUnits(DateInterval $interval)
    {
        $units = array_filter(array(
            'years'   => (int) $interval->y,
            'months'  => (int) $interval->m,
            'days'    => (int) $interval->d,
            'hours'   => (int) $interval->h,
            'minutes' => (int) $interval->i,
            'seconds' => (int) $interval->s,
        ));

        if (empty($units)) {
            return array();
        } else if ((int) $this->config['truncate'] > 0) {
            return array_slice($units, 0, (int) $this->config['truncate']);
        }

        return $units;
    }
31643
public function getDifferenceInMonths($compare = null)
        {
            if (!$compare) {
                $compare = new Date(null, $this->getTimezone());
            }

            $difference = $this->diff($compare);

            list($years, $months) = explode(':', $difference->format('%y:%m'), 2);

            return (($years * 12) + $months) * $difference->format('%r1');
        }
78318
protected function getMonths()
    {
        $intSecondsPerMonth = ($this->isPositive()) ? DateTimeSpan::SECONDS_PER_MONTH : ((-1) * DateTimeSpan::SECONDS_PER_MONTH);
        $intMonths = floor($this->intSeconds / $intSecondsPerMonth);
        if ($this->isNegative()) {
            $intMonths = (-1) * $intMonths;
        }
        return $intMonths;
    }
120758
private static int getDayOfMonth(int dayOfYear, int month, int year) {

        Integer[] newMonths = getAdjustedMonthDays(year);

        if (dayOfYear >= 0) {
            if (month > 0) {
                return dayOfYear - newMonths[month].intValue();
            } else {
                return dayOfYear;
            }
        } else {
            dayOfYear = (isLeapYear(year) ? (dayOfYear + 355)
                    : (dayOfYear + 354));
            if (month > 0) {
                return dayOfYear - newMonths[month].intValue();
            } else {
                return dayOfYear;
            }
        }
    }
860997
public function daysBetween(Date $other) : int
    {
        return $this->dateTime->diff($other->dateTime, true)->days;
    }
1138768
protected function dateIntervalToSeconds($interval): int
    {
        $now = time();
        $dt = new \DateTime();
        $dt->add($interval);
        $ts = $dt->getTimestamp();
        $diff = $ts - $now;
        return $diff;
    }
681358
public static function diffMonths(\DateTime $dateTime1, \DateTime $dateTime2): int
    {
        $diff = $dateTime1->diff($dateTime2);

        return ((int)$diff->format('%y') * 12) + (int)$diff->format('%m');
    }