Return the Julian day n(1 <= n <= 365).

    Leap days are not counted; that is, in all years -- including leap years --
    February 28 is day 59 and March 1 is day 60. It is impossible to explicitly
    refer to the occasional February 29.
508556
def julian_day(year, n):
    
    if n > 59 and isleap(year):
        n += 1
    return datetime(year, 1, 1) + timedelta(n - 1)
996624
function gregorianToJDN(year = 1, month = 1, day = 1, JD_OFFSET = JD_EPOCH_OFFSET_GREGORIAN) {
  const s = Math.floor(year / 4)
          - Math.floor((year - 1) / 4)
          - Math.floor(year / 100)
          + Math.floor((year - 1) / 100)
          + Math.floor(year / 400)
          - Math.floor((year - 1) / 400);
  const t = Math.floor((14 - month) / 12);
  const n = 31 * t * (month - 1)
          + (1 - t) * (59 + s + 30 * (month - 3) + Math.floor((3 * month - 7) / 5))
          + day - 1;
  const j = JD_OFFSET
          + 365 * (year - 1)
          + Math.floor((year - 1) / 4)
          - Math.floor((year - 1) / 100)
          + Math.floor((year - 1) / 400)
          + n;

  return j;
}
836296
def todate(self):
        
        arr = get_gregorian_date_from_julian_day(self.tojulianday())
        return datetime.date(int(arr[0]), int(arr[1]), int(arr[2]))
748441
def jdFromDate(dd, mm, yy):
    ''''''
    a = int((14 - mm) / 12.)
    y = yy + 4800 - a
    m = mm + 12 * a - 3
    jd = dd + int((153 * m + 2) / 5.) \
        + 365 * y + int(y / 4.) - int(y / 100.) \
        + int(y / 400.) - 32045
    if (jd < 2299161):
        jd = dd + int((153 * m + 2) / 5.) \
            + 365 * y + int(y / 4.) - 32083
    return jd
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);
    }
1105977
function(d) {
    var year = later.Y.val(d);

    // shortcut on finding leap years since this function gets called a lot
    // works between 1901 and 2099
    return d.dyExtent || (d.dyExtent = [1, year % 4 ? 365 : 366]);
  }
1085870
function dayOfYear() {
      var is_leap = (ICAL.Time.isLeapYear(this.year) ? 1 : 0);
      var diypm = ICAL.Time.daysInYearPassedMonth;
      return diypm[is_leap][this.month - 1] + this.day;
    }
646550
def calendar_date(jd_integer):
    """"""

    k = jd_integer + 68569
    n = 4 * k // 146097

    k = k - (146097 * n + 3) // 4
    m = 4000 * (k + 1) // 1461001
    k = k - 1461 * m // 4 + 31
    month = 80 * k // 2447
    day = k - 2447 * month // 80
    k = month // 11

    month = month + 2 - 12 * k
    year = 100 * (n - 49) + m + k

    return year, month, day
1212246
function nthWeekDay(countDays, weekDay, year, month, day) {
  let countedDays = 0
  if (countDays >= 0) {
    month = month || 1
    let monthStr = String(month)
    if (monthStr.length === 1) { monthStr = "0" + monthStr }
    day = day || 1
    let dayStr = String(day)
    if (dayStr.length === 1) { dayStr = "0" + dayStr }
    // We stay a minute off midnight to avoid dealing with leap seconds.
    let timestamp = +new Date(`${year}-${monthStr}-${dayStr}T00:01:00Z`)
    let time
    for (let i = 0; i < 366; i++) {
      time = new Date(timestamp)
      if (time.getDay() === weekDay) {countedDays++}
      if (countedDays === countDays) {break}
      timestamp += 24 * 3600 * 1000
    }
    return time
  } else if (countDays < 0) {
    countDays = -countDays
    month = month || 12
    let monthStr = String(month)
    if (monthStr.length === 1) { monthStr = "0" + monthStr }
    day = day || 31
    let dayStr = String(day)
    if (dayStr.length === 1) { dayStr = "0" + dayStr }
    // Starting moment, ms.
    let timestamp = +new Date(`${year}-${monthStr}-${dayStr}T00:01:00Z`)
    let time
    for (let i = 366; i >= 0; i--) {
      time = new Date(timestamp)
      if (time.getDay() === weekDay) {countedDays++}
      if (countedDays === countDays) {break}
      timestamp -= 24 * 3600 * 1000
    }
    return time
  }
}
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)
567245
public static Date getNextDay(Date dt, Long n) {

        Calendar cal = new GregorianCalendar();
        cal.setTime(dt);

        return new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
                                        cal.get(Calendar.DAY_OF_MONTH) + n.intValue()).getTime();

    }
527505
def omer_day(self):
        """"""
        first_omer_day = HebrewDate(self.hdate.year, Months.Nisan, 16)
        omer_day = self._jdn - conv.hdate_to_jdn(first_omer_day) + 1
        if not 0 < omer_day < 50:
            return 0
        return omer_day
781916
public function jdToYmd($julian_day)
    {
        // Find the year, by adding one month at a time to use up the remaining days.
        $year  = $this->jdToY($julian_day);
        $month = 1;
        $day   = $julian_day - $this->yToJd($year) + 1;

        while ($day > $this->daysInMonth($year, $month)) {
            $day -= $this->daysInMonth($year, $month);
            $month++;
        }

        // PHP 5.4 and earlier converted non leap-year Adar into month 6, instead of month 7.
        $month -= ($month === 7 && $this->options[self::EMULATE_BUG_54254] && !$this->isLeapYear($year)) ? 1 : 0;

        return array($year, $month, $day);
    }
621042
def days_in_month(month = self.month, year = self.year)
      (month == 12 && kabisa?(year) || month.odd?) ? 30 : 29
    end
1173254
@Override
	public double getDaycountFraction(LocalDate startDate, LocalDate endDate) {
		if(startDate.isAfter(endDate)) {
			return -getDaycountFraction(endDate,startDate);
		}

		double daysPerYear = 365.0;

		// Check startDate for leap year
		if (startDate.isLeapYear()) {
			LocalDate leapDayStart = LocalDate.of(startDate.getYear(), Month.FEBRUARY, 29);
			if(startDate.isBefore(leapDayStart) && !endDate.isBefore(leapDayStart)) {
				daysPerYear = 366.0;
			}
		}

		// Check endDate for leap year
		if (endDate.isLeapYear()){
			LocalDate leapDayEnd = LocalDate.of(endDate.getYear(),  Month.FEBRUARY,  29);
			if(startDate.isBefore(leapDayEnd) && !endDate.isBefore(leapDayEnd)) {
				daysPerYear = 366.0;
			}
		}

		// Check in-between years for leap year
		for(int year = startDate.getYear()+1; year < endDate.getYear(); year++) {
			if(IsoChronology.INSTANCE.isLeapYear(year)) {
				daysPerYear = 366.0;
			}
		}

		double daycountFraction = getDaycount(startDate, endDate) / daysPerYear;

		return daycountFraction;
	}
24016
def calculate_leapdays(init_date, final_date):
    """"""

    leap_days = (final_date.year - 1) // 4 - (init_date.year - 1) // 4
    leap_days -= (final_date.year - 1) // 100 - (init_date.year - 1) // 100
    leap_days += (final_date.year - 1) // 400 - (init_date.year - 1) // 400

    # TODO: Internal date correction (e.g. init_date is 1-March or later)

    return datetime.timedelta(days=leap_days)
1165225
def to_jd(year, month, day):
    ''''''

    gyear = year + 78
    leap = isleap(gyear)
    # // Is this a leap year ?

    # 22 - leap = 21 if leap, 22 non-leap
    start = gregorian.to_jd(gyear, 3, 22 - leap)
    if leap:
        Caitra = 31
    else:
        Caitra = 30

    if month == 1:
        jd = start + (day - 1)
    else:
        jd = start + Caitra
        m = month - 2
        m = min(m, 5)
        jd += m * 31
        if month >= 8:
            m = month - 7
            jd += m * 30

        jd += day - 1

    return jd