Converts a calendar date to a Julian day count

@param  int   $iy   Year
@param  int   $im   Month
@param  int   $id   Day
@param  float $djm0 JD part 1
@param  float $djm  JD part 2

@return int
976211
private static function iauCal2jd($iy, $im, $id, &$djm0, &$djm)
    {
        $j;
        $ly;
        $my;
        $iypmy;
        /* Earliest year allowed (4800BC) */
        $IYMIN = -4799;
        /* Month lengths in days */
        $mtab = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
        /* Preset status. */
        $j = 0;
        /* Validate year and month. */
        if ($iy < $IYMIN) {
            return -1;
        }
        if ($im < 1 || $im > 12) {
            return -2;
        }
        /* If February in a leap year, 1, otherwise 0. */
        $ly = (($im == 2) && !($iy % 4) && ($iy % 100 || !($iy % 400)));
        /* Validate day, taking into account leap years. */
        if (($id < 1) || ($id > ($mtab[$im - 1] + $ly))) {
            $j = -3;
        }
        /* Return result. */
        $my    = intval(($im - 14) / 12);
        $iypmy = intval($iy + $my);
        $djm0  = 2400000.5;
        $djm   = (double)(intval((1461 * ($iypmy + 4800)) / 4) +
          intval((367 * intval($im - 2 - 12 * $my)) / 12) -
          intval((3 * (intval(($iypmy + 4900) / 100))) / 4) +
          intval($id - 2432076));

        /* Return status. */

        return $j;
    }
118483
def jdToDate(jd):
    ''''''
    if (jd > 2299160):
        # After 5/10/1582, Gregorian calendar
        a = jd + 32044
        b = int((4 * a + 3) / 146097.)
        c = a - int((b * 146097) / 4.)
    else:
        b = 0
        c = jd + 32082
    d = int((4 * c + 3) / 1461.)
    e = c - int((1461 * d) / 4.)
    m = int((5 * e + 2) / 153.)
    day = e - int((153 * m + 2) / 5.) + 1
    month = m + 3 - 12 * int(m / 10.)
    year = b * 100 + d - 4800 + int(m / 10.)
    return [day, month, year]
429759
def hdate_to_jdn(date):
    
    day = date.day
    month = date.month
    if date.month == 13:
        month = 6
    if date.month == 14:
        month = 6
        day += 30

    # Calculate days since 1,1,3744
    day = _days_from_3744(date.year) + (59 * (month - 1) + 1) // 2 + day

    # length of year
    length_of_year = get_size_of_hebrew_year(date.year)
    # Special cases for this year
    if length_of_year % 10 > 4 and month > 2:  # long Heshvan
        day += 1
    if length_of_year % 10 < 4 and month > 3:  # short Kislev
        day -= 1
    if length_of_year > 365 and month > 6:  # leap year
        day += 30

    # adjust to julian
    return day + 1715118
303717
def julian_datetime(julianday, milisecond=0):
    
    if julianday <= 1721423:
        # no datetime before year 1
        return None

    a = julianday + 1
    if a > 2299160:
        alpha = math.trunc((a - 1867216.25) / 36524.25)
        a += 1 + alpha - alpha // 4
    b = a + (1524 if a > 1721423 else 1158)
    c = math.trunc((b - 122.1) / 365.25)
    d = math.trunc(365.25 * c)
    e = math.trunc((b - d) / 30.6001)

    day = b - d - math.trunc(30.6001 * e)
    month = e - (1 if e < 13.5 else 13)
    year = c - (4716 if month > 2.5 else 4715)

    hour, milisecond = divmod(milisecond, 1000 * 60 * 60)
    minute, milisecond = divmod(milisecond, 1000 * 60)
    second, milisecond = divmod(milisecond, 1000)

    return datetime.datetime(year, month, day,
                             hour, minute, second, milisecond)
1136619
public static void jdToCE(int julianDay, int jdEpochOffset, int[] fields) {
        int c4; // number of 4 year cycle (1461 days)
        int[] r4 = new int[1]; // remainder of 4 year cycle, always positive

        c4 = floorDivide(julianDay - jdEpochOffset, 1461, r4);

        // exteded year
        fields[0] = 4 * c4 + (r4[0]/365 - r4[0]/1460); // 4 * <number of 4year cycle> + <years within the last cycle>

        int doy = (r4[0] == 1460) ? 365 : (r4[0] % 365); // days in present year

        // month
        fields[1] = doy / 30; // 30 -> Coptic/Ethiopic month length up to 12th month
        // day
        fields[2] = (doy % 30) + 1; // 1-based days in a month
    }
367565
public static function jdDayOfWeek($julian_day, $mode)
    {
        $day_of_week = ($julian_day + 1) % 7;
        if ($day_of_week < 0) {
            $day_of_week += 7;
        }

        switch ($mode) {
            case 1: // 1, not CAL_DOW_LONG - see bug 67960
                return self::$DAY_NAMES[$day_of_week];

            case 2: // 2, not CAL_DOW_SHORT - see bug 67960
                return self::$DAY_NAMES_SHORT[$day_of_week];

            default: // CAL_DOW_DAYNO or anything else
                return $day_of_week;
        }
    }
515630
public static int ceToJD(long year, int month, int day, int jdEpochOffset) {

        // Julian<->Ethiopic algorithms from:
        // "Calendars in Ethiopia", Berhanu Beyene, Manfred Kudlek, International Conference
        // of Ethiopian Studies XV, Hamburg, 2003

        // handle month > 12, < 0 (e.g. from add/set)
        if ( month >= 0 ) {
            year += month/13;
            month %= 13;
        } else {
            ++month;
            year += month/13 - 1;
            month = month%13 + 12;
        }
        return (int) (
            jdEpochOffset           // difference from Julian epoch to 1,1,1
            + 365 * year            // number of days from years
            + floorDivide(year, 4)  // extra day of leap year
            + 30 * month            // number of days from months (months are 0-based)
            + day - 1               // number of days for present month (1 based)
            );
    }
281842
def julian_day(t: date) -> int:
    """"""
    # Compute the number of days from January 1, 2000 to date t
    dt = t - julian_base_date
    # Add the julian base number to the number of days from the julian base date to date t
    return julian_base_number + dt.days
1369959
public static function jdToGregorian($julian_day)
    {
        // PHP has different limits on 32 and 64 bit systems.
        $MAX_JD = PHP_INT_SIZE == 4 ? 536838866 : 2305843009213661906;

        return self::jdToCalendar(self::$gregorian_calendar, $julian_day, 1, $MAX_JD);
    }
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];
	}
508184
public function convert_to_timestamp($year, $month, $day, $hour = 0, $minute = 0) {
        $gregorianinfo = $this->convert_to_gregorian($year, $month, $day, $hour, $minute);
        return make_timestamp(
            $gregorianinfo['year'],
            $gregorianinfo['month'],
            $gregorianinfo['day'],
            $gregorianinfo['hour'],
            $gregorianinfo['minute'],
            0);
    }
375395
def to_jd(year, month, day):
    ''''''
    gy = year - 1 + EPOCH_GREGORIAN_YEAR

    if month != 20:
        m = 0
    else:
        if isleap(gy + 1):
            m = -14
        else:
            m = -15
    return gregorian.to_jd(gy, 3, 20) + (19 * (month - 1)) + m + day
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;
        }
    }
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' ) );

   }
686137
private void addMonth(int i) {
        Calendar cal = Calendar.getInstance();
        cal.set(getDisplayYear(), getDisplayMonth() - 1, 1);
        int month = cal.get(Calendar.MONTH) + 1;
        if (i > 0 && month == 12) {
            addYear(1);
        }

        if (i < 0 && month == 1) {
            addYear(-1);
        }
        cal.add(Calendar.MONTH, i);

        monthTextField.setText(String.valueOf(cal.get(Calendar.MONTH) + 1));

    }
1062130
public static int yyMMdd(long time) {
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(time);
        return cal.get(Calendar.YEAR) % 100 * 10000 + (cal.get(Calendar.MONTH) + 1) * 100 + cal.get(Calendar.DAY_OF_MONTH);
    }
939548
public static function getDaysByMonth($month, $year): int
    {
        $months = self::getDaysByMonthsOfYear($year);
        $value = $months [$month - 1];
        return !$value ? 0 : $value;
    }