How long between an event and a given julian day
Return result as a gedcom-style age string.

@param int $jd date for calculation

@return string
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';
    }
136743
public function getJavascriptTimestamp()
    {
        $date = new \DateTime($this->startDate->format('Y-m-d H:i:s'));
        $javascriptTimestamp = $date->getTimestamp()*1000;
        return $javascriptTimestamp;
    }
1237770
def from_jd(jd):
    ''''''
    jd = trunc(jd) + 0.5

    depoch = jd - to_jd(475, 1, 1)
    cycle = trunc(depoch / 1029983)
    cyear = (depoch % 1029983)

    if cyear == 1029982:
        ycycle = 2820
    else:
        aux1 = trunc(cyear / 366)
        aux2 = cyear % 366
        ycycle = trunc(((2134 * aux1) + (2816 * aux2) + 2815) / 1028522) + aux1 + 1

    year = ycycle + (2820 * cycle) + 474

    if (year <= 0):
        year -= 1

    yday = (jd - to_jd(year, 1, 1)) + 1

    if yday <= 186:
        month = ceil(yday / 31)
    else:
        month = ceil((yday - 6) / 30)

    day = int(jd - to_jd(year, month, 1)) + 1

    return (year, month, day)
1109594
function lastday ($month,$day,$year)

	{

		$lastdayen=date("d",mktime(0,0,0,$month+1,0,$year));

		list( $jyear, $jmonth, $jday ) = $this->gregorian_to_jalali($year, $month, $day);

		$lastdatep=$jday;

		$jday=$jday2;

		while($jday2!="1")

		{

			if($day<$lastdayen)

			{

				$day++;

				list( $jyear, $jmonth, $jday2 ) = $this->gregorian_to_jalali($year, $month, $day);

				if($pdate2=="1") break;

				if($pdate2!="1") $lastdatep++;

			}

			else

			{

				$day=0;

				$month++;

				if($month==13)

				{

					$month="1";

					$year++;

				}

			}



		}

		return $lastdatep-1;

	}
92150
private static function iauJd2cal($dj1, $dj2, &$iy, &$im, &$id, &$fd)
    {
        /* Minimum and maximum allowed JD */
        $DJMIN = -68569.5;
        $DJMAX = 1e9;
        $jd;
        $l;
        $n;
        $i;
        $k;
        $dj;
        $d1;
        $d2;
        $f1;
        $f2;
        $f;
        $d;
        /* Verify date is acceptable. */
        $dj = $dj1 + $dj2;
        if ($dj < $DJMIN || $dj > $DJMAX) {
            return -1;
        }
        /* Copy the date, big then small, and re-align to midnight. */
        if ($dj1 >= $dj2) {
            $d1 = $dj1;
            $d2 = $dj2;
        } else {
            $d1 = $dj2;
            $d2 = $dj1;
        }
        $d2 -= 0.5;
        /* Separate day and fraction. */
        $f1 = fmod($d1, 1.0);
        $f2 = fmod($d2, 1.0);
        $f  = fmod($f1 + $f2, 1.0);
        if ($f < 0.0) {
            $f += 1.0;
        }
        $d  = floor($d1 - $f1) + floor($d2 - $f2) + floor($f1 + $f2 - $f);
        $jd = floor($d) + 1;
        /* Express day in Gregorian calendar. */
        // Integer division parts of this block was modified in the PHP translation
        $l = $jd + 68569;
        $n = intval((4 * $l) / 146097);
        $l -= intval((146097 * $n + 3) / 4);
        $i = intval((4000 * ($l + 1)) / 1461001);
        $l -= ((1461 * $i) / 4) - 31;
        $k  = intval((80 * $l) / 2447);
        $id = round($l - (2447 * $k) / 80);
        $l  = intval($k / 11);
        $im = (int)($k + 2 - 12 * $l);
        $iy = (int)(100 * ($n - 49) + $i + $l);
        $fd = $f;

        return 0;
    }
66114
public function jdToYmd($julian_day)
    {
        $depoch = $julian_day - 2121446; // 1 Farvardīn 475
        $cycle  = (int) floor($depoch / 1029983);
        $cyear  = $this->mod($depoch, 1029983);
        if ($cyear == 1029982) {
            $ycycle = 2820;
        } else {
            $aux1   = (int) ($cyear / 366);
            $aux2   = $cyear % 366;
            $ycycle = (int) (((2134 * $aux1) + (2816 * $aux2) + 2815) / 1028522) + $aux1 + 1;
        }
        $year = $ycycle + (2820 * $cycle) + 474;

        // If we allowed negative years, we would deal with them here.
        $yday  = $julian_day - $this->ymdToJd($year, 1, 1) + 1;
        $month = ($yday <= 186) ? ceil($yday / 31) : ceil(($yday - 6) / 30);
        $day   = $julian_day - $this->ymdToJd($year, $month, 1) + 1;

        return array((int) $year, (int) $month, (int) $day);
    }
453429
public static String getDateAsString(final double JULIAN_DAY, final int TIMEZONE_OFFSET) throws Exception {
        if (JULIAN_DAY == -1) return "NO RISE/SET/TRANSIT FOR THIS OBSERVER/DATE";

        int date[] = SunMoonCalculator.getDate(JULIAN_DAY);
        return date[0] + "/" + date[1] + "/" + date[2] + " " + ((date[3] + TIMEZONE_OFFSET) % 24) + ":" + date[4] + ":" + date[5] + " UT";
    }
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
632055
protected function jdToYear(int $jd): int
    {
        if ($jd === 0) {
            return 0;
        }

        $gregorian = new GregorianCalendar();
        [$y] = $gregorian->jdToYmd($jd);

        return $y;
    }
762876
protected function yToJd($year)
    {
        $div19 = (int) (($year - 1) / 19);
        $mod19 = ($year - 1) % 19;

        $months      = 235 * $div19 + 12 * $mod19 + (int) ((7 * $mod19 + 1) / 19);
        $parts       = 204 + 793 * ($months % 1080);
        $hours       = 5 + 12 * $months + 793 * (int) ($months / 1080) + (int) ($parts / 1080);
        $conjunction = 1080 * ($hours % 24) + ($parts % 1080);
        $julian_day  = 1 + 29 * $months + (int) ($hours / 24);

        if ($conjunction >= 19440 ||
            $julian_day % 7 === 2 && $conjunction >= 9924 && !$this->isLeapYear($year) ||
            $julian_day % 7 === 1 && $conjunction >= 16789 && $this->isLeapYear($year - 1)
        ) {
            $julian_day++;
        }

        // The actual year start depends on the day of the week
        return $julian_day + self::$ROSH_HASHANAH[$julian_day % 7];
    }
753074
public function jdToYmd($julian_day)
    {
        $c = $julian_day + 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  = $d - 4800 + (int) ($m / 10);
        if ($year < 1) {
            // 0 is 1 BCE, -1 is 2 BCE, etc.
            $year--;
        }

        return array($year, $month, $day);
    }
734997
protected function jdToIslamic($jd)
    {
        $l = (int)$jd - 1948440 + 10632;
        $n = (int)(($l - 1) / 10631);
        $l = $l - 10631 * $n + 354;
        $j = (int)((10985 - $l) / 5316) * (int)((50 * $l) / 17719) 
            + (int)($l / 5670) * (int)((43 * $l) / 15238);
        $l = $l - (int)((30 - $j) / 15) * (int)((17719 * $j) / 50) 
            - (int)($j / 16) * (int)((15238 * $j) / 43) + 29;
        $m = (int)((24 * $l) / 709);
        $d = $l - (int)((709 * $m) / 24);
        $y = (int)(30 * $n + $j - 30);
        
        return array($y, $m, $d);
    }
788618
def to_jd(year, month, day):
    ''''''

    legal_date(year, month, day)

    # Algorithm as given in Meeus, Astronomical Algorithms, Chapter 7, page 61

    if month <= 2:
        year -= 1
        month += 12

    return (trunc((365.25 * (year + 4716))) + trunc((30.6001 * (month + 1))) + day) - 1524.5
492339
protected static function julian2georgian($julianDayNumber) {
        
        $j = 4 * $julianDayNumber + 139361631;
        $j += self::division(self::division(4 * $julianDayNumber + 183187720, 146097) * 3, 4) * 4 - 3908;
        $i = self::division(($j % 1461), 4) * 5 + 308;
        
        $gDay   = self::division(($i % 153), 5) + 1;
        $gMonth = (self::division($i, 153) % 12) + 1;
        $gYear  = self::division($j, 1461) - 100100 + self::division(8 - $gMonth, 6);
        
        return [$gYear, $gMonth, $gDay];
    }
1028118
def jd(date = self)
      y30 = (date.year / 30.0).floor
      day_number = 1948084 + y30 * 10631 + day_of_year(date)

      if date.year % 30 == 0
        day_number
      else
        day_number + DAYS_IN_30_YEARS[date.year - y30 * 30 - 1]
      end
    end
598036
def gdate_to_jdn(date):
    
    not_jan_or_feb = (14 - date.month) // 12
    year_since_4800bc = date.year + 4800 - not_jan_or_feb
    month_since_4800bc = date.month + 12 * not_jan_or_feb - 3
    jdn = date.day + (153 * month_since_4800bc + 2) // 5 \
        + 365 * year_since_4800bc \
        + (year_since_4800bc // 4 - year_since_4800bc // 100 +
           year_since_4800bc // 400) - 32045
    return jdn
372650
function(jd) {
			var gregorianCalendar =  $.calendars.instance();
			var gregorianDate = gregorianCalendar.fromJD(jd);
			var gregorianYear = gregorianDate.year();
			var gregorianDayOfYear = gregorianDate.dayOfYear();
			var nepaliYear = gregorianYear + 56; //this is not final, it could be also +57 but +56 is always true for 1st Jan.
			this._createMissingCalendarData(nepaliYear);
			var nepaliMonth = 9; // Jan 1 always fall in Nepali month Paush which is the 9th month of Nepali calendar.
			// Get the Nepali day in Paush (month 9) of 1st January 
			var dayOfFirstJanInPaush = this.NEPALI_CALENDAR_DATA[nepaliYear][0];
			// Check how many days are left of Paush .
			// Days calculated from 1st Jan till the end of the actual Nepali month, 
			// we use this value to check if the gregorian Date is in the actual Nepali month.
			var daysSinceJanFirstToEndOfNepaliMonth =
				this.NEPALI_CALENDAR_DATA[nepaliYear][nepaliMonth] - dayOfFirstJanInPaush + 1;
			// If the gregorian day-of-year is smaller o equal than the sum of days between the 1st January and 
			// the end of the actual nepali month we found the correct nepali month.
			// Example: 
			// The 4th February 2011 is the gregorianDayOfYear 35 (31 days of January + 4)
			// 1st January 2011 is in the nepali year 2067, where 1st. January is in the 17th day of Paush (9th month)
			// In 2067 Paush has 30days, This means (30-17+1=14) there are 14days between 1st January and end of Paush 
			// (including 17th January)
			// The gregorianDayOfYear (35) is bigger than 14, so we check the next month
			// The next nepali month (Mangh) has 29 days 
			// 29+14=43, this is bigger than gregorianDayOfYear(35) so, we found the correct nepali month
			while (gregorianDayOfYear > daysSinceJanFirstToEndOfNepaliMonth) {
				nepaliMonth++;
				if (nepaliMonth > 12) {
					nepaliMonth = 1;
					nepaliYear++;
				}	
				daysSinceJanFirstToEndOfNepaliMonth += this.NEPALI_CALENDAR_DATA[nepaliYear][nepaliMonth];
			}
			// The last step is to calculate the nepali day-of-month
			// to continue our example from before:
			// we calculated there are 43 days from 1st. January (17 Paush) till end of Mangh (29 days)
			// when we subtract from this 43 days the day-of-year of the the Gregorian date (35),
			// we know how far the searched day is away from the end of the Nepali month.
			// So we simply subtract this number from the amount of days in this month (30) 
			var nepaliDayOfMonth = this.NEPALI_CALENDAR_DATA[nepaliYear][nepaliMonth] -
				(daysSinceJanFirstToEndOfNepaliMonth - gregorianDayOfYear);		
			return this.newDate(nepaliYear, nepaliMonth, nepaliDayOfMonth);
		}