Converts a Julian Day Count to a Julian Calendar Date.

Shim implementation of JDToJulian()

@link https://php.net/JDToJulian

@param int $julian_day A Julian Day number

@return string A string of the form "month/day/year"
181393
public static function jdToJulian($julian_day)
    {
        // PHP has different limits on 32 and 64 bit systems.
        $MAX_JD = PHP_INT_SIZE == 4 ? 536838829 : 784368370349;

        return self::jdToCalendar(self::$julian_calendar, $julian_day, 1, $MAX_JD);
    }
181701
protected function formatDayZeros(): string
    {
        if ($this->day > 9) {
            return I18N::digits($this->day);
        }

        return I18N::digits('0' . $this->day);
    }
693459
public function jdToHebrew($julian_day, $alafim_garesh, $alafim, $gereshayim)
    {
        list($year, $month, $day) = $this->jdToYmd($julian_day);

        return
            $this->numberToHebrewNumeralsIso8859($day, $gereshayim) . ' ' .
            $this->hebrewMonthName($year, $month) . ' ' .
            $this->yearToHebrewNumerals($year, $alafim_garesh, $alafim, $gereshayim);
    }
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;
    }
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
484099
public function getAgeFull(int $jd): string
    {
        if ($this->year === 0 || $jd === 0) {
            return '';
        }
        if ($this->minimum_julian_day < $jd && $this->maximum_julian_day > $jd) {
            return '';
        }
        if ($this->minimum_julian_day === $jd) {
            return '';
        }
        if ($jd < $this->minimum_julian_day) {
            return view('icons/warning');
        }
        [$y, $m, $d] = $this->calendar->jdToYmd($jd);
        $dy = $y - $this->year;
        $dm = $m - max($this->month, 1);
        $dd = $d - max($this->day, 1);
        if ($dd < 0) {
            $dm--;
        }
        if ($dm < 0) {
            $dm += $this->calendar->monthsInYear();
            $dy--;
        }
        // Age in years?
        if ($dy > 1) {
            return $dy . 'y';
        }
        $dm += $dy * $this->calendar->monthsInYear();
        // Age in months?
        if ($dm > 1) {
            return $dm . 'm';
        }

        // Age in days?
        return ($jd - $this->minimum_julian_day) . 'd';
    }
884221
public static function julianToJd($month, $day, $year)
    {
        if ($year == 0) {
            return 0;
        } else {
            return self::$julian_calendar->ymdToJd($year, $month, $day);
        }
    }
1018837
public static int[] getDate(final double JULIAN_DAY) throws Exception {
        if (JULIAN_DAY < 2299160.0 && JULIAN_DAY >= 2299150.0) {
            throw new Exception("invalid julian day " + JULIAN_DAY + ". This date does not exist.");
        }

        // The conversion formulas are from Meeus,
        // Chapter 7.
        double Z = Math.floor(JULIAN_DAY + 0.5);
        double F = JULIAN_DAY + 0.5 - Z;
        double A = Z;
        if (Z >= 2299161D) {
            int a = (int) ((Z - 1867216.25) / 36524.25);
            A += 1 + a - a / 4;
        }
        double B = A + 1524;
        int    C = (int) ((B - 122.1) / 365.25);
        int    D = (int) (C * 365.25);
        int    E = (int) ((B - D) / 30.6001);

        double exactDay = F + B - D - (int) (30.6001 * E);
        int    day      = (int) exactDay;
        int    month    = (E < 14) ? E - 1 : E - 13;
        int    year     = C - 4715;
        if (month > 2) year--;
        double h = ((exactDay - day) * SECONDS_PER_DAY) / 3600.0;

        int    hour   = (int) h;
        double m      = (h - hour) * 60.0;
        int    minute = (int) m;
        int    second = (int) ((m - minute) * 60.0);

        return new int[] { year, month, day, hour, minute, second };
    }
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;
        }
    }
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;
    }
514918
public function ymdToJd($year, $month, $day)
    {
        if ($month < 1 || $month > $this->monthsInYear()) {
            throw new InvalidArgumentException('Month ' . $month . ' is invalid for this calendar');
        }

        return $day + 29 * ($month - 1) + (int) ((6 * $month - 1) / 11) + $year * 354 + (int) ((3 + 11 * $year) / 30) + 1948085;
    }
525765
def gregorian_to_julian(day):
    
    before_march = 1 if day.month < MARCH else 0

    #
    # Number of months since March
    #
    month_index = day.month + MONTHS_PER_YEAR * before_march - MARCH

    #
    # Number of years (year starts on March) since 4800 BC
    #
    years_elapsed = day.year - JULIAN_START_YEAR - before_march

    total_days_in_previous_months = (153 * month_index + 2) // 5
    total_days_in_previous_years = 365 * years_elapsed
    total_leap_days = (
        (years_elapsed // 4) -
        (years_elapsed // 100) +
        (years_elapsed // 400)
    )

    return sum([
        day.day,
        total_days_in_previous_months,
        total_days_in_previous_years,
        total_leap_days,
        -32045,      # Offset to get January 1, 4713 equal to 0
    ])
1147796
public function ymdToJd($year, $month, $day)
    {
        return
            $this->yToJd($year) +
            self::$CUMULATIVE_DAYS[$this->isLeapYear($year)][$this->yearType($year)][$month] +
            $day - 1;
    }
1130908
def julian(mon, day, year):
    
    ig = 15 + 31 * (10 + 12 * 1582)
    if year == 0:
        print("Julian no can do")
        return
    if year < 0:
        year = year + 1
    if mon > 2:
        julian_year = year
        julian_month = mon + 1
    else:
        julian_year = year - 1
        julian_month = mon + 13
    j1 = int(365.25 * julian_year)
    j2 = int(30.6001 * julian_month)
    j3 = day + 1720995
    julian_day = j1 + j2 + j3
    if day + 31 * (mon + 12 * year) >= ig:
        jadj = int(0.01 * julian_year)
        julian_day = julian_day + 2 - jadj + int(0.25 * jadj)
    return julian_day
233789
private static function jdMonthNameJewishMonths($julian_day)
    {
        list(, , $year) = explode('/', self::jdToCalendar(self::$jewish_calendar, $julian_day, 347998, 324542846));

        if (self::$jewish_calendar->isLeapYear($year)) {
            return self::shouldEmulateBug54254() ? self::$MONTH_NAMES_JEWISH_54254 : self::$MONTH_NAMES_JEWISH_LEAP_YEAR;
        } else {
            return self::shouldEmulateBug54254() ? self::$MONTH_NAMES_JEWISH_54254 : self::$MONTH_NAMES_JEWISH;
        }
    }
358071
def julianDay(year, month, day):
    ""
    hr = 12  #make sure you fall into right day, middle is save
    t = time.mktime((year, month, day, hr, 0, 0.0, 0, 0, -1))
    julDay = time.localtime(t)[7]
    return julDay
1171334
def julian_day(year, month=1, day=1):
    """"""
    janfeb = month < 3
    return (day
            + 1461 * (year + 4800 - janfeb) // 4
            + 367 * (month - 2 + janfeb * 12) // 12
            - 3 * ((year + 4900 - janfeb) // 100) // 4
            - 32075)