FormattedPHPToExcel

@param    integer    $year
@param    integer    $month
@param    integer    $day
@param    integer    $hours
@param    integer    $minutes
@param    integer    $seconds
@return   integer    Excel date/time value
348279
public static function FormattedPHPToExcel($year, $month, $day, $hours = 0, $minutes = 0, $seconds = 0)
    {
        if (self::$excelBaseDate == self::CALENDAR_WINDOWS_1900) {
            //
            //    Fudge factor for the erroneous fact that the year 1900 is treated as a Leap Year in MS Excel
            //    This affects every date following 28th February 1900
            //
            $excel1900isLeapYear = true;
            if (($year == 1900) && ($month <= 2)) {
                $excel1900isLeapYear = false;
            }
            $myexcelBaseDate = 2415020;
        } else {
            $myexcelBaseDate = 2416481;
            $excel1900isLeapYear = false;
        }

        //    Julian base date Adjustment
        if ($month > 2) {
            $month -= 3;
        } else {
            $month += 9;
            --$year;
        }

        //    Calculate the Julian Date, then subtract the Excel base date (JD 2415020 = 31-Dec-1899 Giving Excel Date of 0)
        $century = substr($year, 0, 2);
        $decade = substr($year, 2, 2);
        $excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $myexcelBaseDate + $excel1900isLeapYear;

        $excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400;

        return (float) $excelDate + $excelTime;
    }
632596
public static function days_in_month($month, $year = null)
	{
		$year  = ! empty($year) ? (int) $year : (int) date('Y');
		$month = (int) $month;

		if ($month < 1 or $month > 12)
		{
			throw new \UnexpectedValueException('Invalid input for month given.');
		}
		elseif ($month == 2)
		{
			if ($year % 400 == 0 or ($year % 4 == 0 and $year % 100 != 0))
			{
				return 29;
			}
		}

		$days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
		return $days_in_month[$month-1];
	}
1194834
protected static function checkDate($day, $month, $year)
    {
        // Tolerate both day-month and month-day order
        if ((12 <= $month && $month <= 31) && $day <= 12) {
            $m = $month;
            $month = $day;
            $day = $m;
        }
        if ($day > 31 || $month > 12) {
            return false;
        }
        if (!(1900 <= $year && $year <= 2019)) {
            return false;
        }

        return [$day, $month, $year];
    }
1058326
public static function lastDayOfMonth($month = null, $year = null, $format = 'Y-m-d')
    {
        $year = $year ? $year : date('Y');
        $month = $month ? $month : date('m');
        return date($format, mktime(0, 0, 0, $month + 1, 0, $year));
    }
939548
public static function getDaysByMonth($month, $year): int
    {
        $months = self::getDaysByMonthsOfYear($year);
        $value = $months [$month - 1];
        return !$value ? 0 : $value;
    }
22557
private static function calDaysInMonthCalendar(CalendarInterface $calendar, $year, $month)
    {
        try {
            return $calendar->daysInMonth($year, $month);
        } catch (InvalidArgumentException $ex) {
            $error_msg = PHP_VERSION_ID < 70200 ? 'invalid date.' : 'invalid date';

            return trigger_error($error_msg, E_USER_WARNING);
        }
    }
415747
public function write_date($row, $col, $date, $format = null) {
        $getdate = usergetdate($date);
        $exceldate = PHPExcel_Shared_Date::FormattedPHPToExcel(
            $getdate['year'],
            $getdate['mon'],
            $getdate['mday'],
            $getdate['hours'],
            $getdate['minutes'],
            $getdate['seconds']
        );

        $this->worksheet->setCellValueByColumnAndRow($col, $row+1, $exceldate);
        $this->worksheet->getStyleByColumnAndRow($col, $row+1)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX22);
        $this->apply_format($row, $col, $format);
    }
796122
public static function gregorianToJulian(int $year, int $month, int $day)
    {
        if ($month < 3)
        {
            $year -= 1;
            $month += 12;
        }

        $a = floor($year / 100.0);
        $b = ($year === 1582 && ($month > 10 || ($month === 10 && $day > 4)) ? -10 :
            ($year === 1582 && $month === 10 ? 0 :
                ($year < 1583 ? 0 : 2 - $a + floor($a / 4.0))));

        return floor(365.25 * ($year + 4716)) + floor(30.6001 * ($month + 1)) + $day + $b - 1524;
    }
897903
public function setDate($year, $month, $day)
    {
        return parent::setDate(self::$yearMustAlwaysBe, self::$monthMustAlwaysBe, self::$dayMustAlwaysBe);
    }
274583
public function setDate($year, $month, $day)
    {
        try {
            $this->getDateObject()->setDate($year, $month, $day);
        } catch (\Exception $e) {
            throw new DateTimeObjectException($e->getMessage());
        }

        return $this;
    }
443681
public static function ageRange($year, $month = null, $day = null, $steps = 1) {
		if ($month == null && $day == null) {
			$age = (int)date('Y') - $year - 1;
		} elseif ($day == null) {
			if ($month >= (int)date('m')) {
				$age = (int)date('Y') - $year - 1;
			} else {
				$age = (int)date('Y') - $year;
			}
		} else {
			if ($month > (int)date('m') || ($month == (int)date('m') && $day > (int)date('d'))) {
				$age = (int)date('Y') - $year - 1;
			} else {
				$age = (int)date('Y') - $year;
			}
		}
		if ($age % $steps == 0) {
			$lowerRange = $age - $steps + 1;
			$upperRange = $age;
		} else {
			$lowerRange = $age - ($age % $steps) + 1;
			$upperRange = $age - ($age % $steps) + $steps;
		}
		if ($lowerRange == $upperRange) {
			return $upperRange;
		}
		return [$lowerRange, $upperRange];
	}
535752
public static function createGregorianDate($year = null, $month = null, $day = null, $timezone = null)
    {
        return static::createGregorian($year, $month, $day, null, null, null, $timezone);
    }
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;
        }
    }
1075619
public function setDate($year, $month, $day)
    {
        list($year, $month, $day) = self::getGregorian($year, $month, $day);

        return parent::setDate($year, $month, $day);
    }
424128
public static function GetDaysInMonth( int $year, int $month ) : int
   {

      $dt = new \DateTime();
      $dt->setDate( $year, $month, 2 );
      $dt->setTime( 0, 0, 2 );

      return \intval( $dt->format( 't' ) );

   }
604860
public function setEndDate(int $day, int $month, int $year): self
    {
        $this->endDate = [$day, $month, $year];

        return $this;
    }
142320
public function ymdToJd($year, $month, $day)
    {
        if ($month < 1 || $month > $this->monthsInYear()) {
            throw new InvalidArgumentException('Month ' . $month . ' is invalid for this calendar');
        }

        if ($year < 0) {
            // 1 BCE is 0, 2 BCE is -1, etc.
            ++$year;
        }
        $a     = (int) ((14 - $month) / 12);
        $year  = $year + 4800 - $a;
        $month = $month + 12 * $a - 3;

        return $day + (int) ((153 * $month + 2) / 5) + 365 * $year + (int) ($year / 4) - (int) ($year / 100) + (int) ($year / 400) - 32045;
    }