Returns month-of-year. 0-based.

@param dayOfYear  day-of-year
@param year  a year
@return month-of-year
542233
private static int getMonthOfYear(int dayOfYear, int year) {

        Integer[] newMonths = getAdjustedMonthDays(year);

        if (dayOfYear >= 0) {
            for (int i = 0; i < newMonths.length; i++) {
                if (dayOfYear < newMonths[i].intValue()) {
                    return i - 1;
                }
            }
            return 11;
        } else {
            dayOfYear = (isLeapYear(year) ? (dayOfYear + 355)
                    : (dayOfYear + 354));
            for (int i = 0; i < newMonths.length; i++) {
                if (dayOfYear < newMonths[i].intValue()) {
                    return i - 1;
                }
            }
            return 11;
        }
    }
991198
public static int getDayOfYear(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.get(Calendar.DAY_OF_YEAR);
    }
330635
private int getMonthLength(int year, int month) {
        int days = DAYS_IN_MONTH[month];
        if (month == FEBRUARY && isLeapYear(year)) {
            days++;
        }
        return days;
    }
462443
public int numOccurrences(int year, int month, int day) {
        DateTimeFormatter parser = ISODateTimeFormat.date();
        DateTime date = parser.parseDateTime(year + "-" + month + "-" + "01");
        Calendar cal = Calendar.getInstance();
        cal.setTime(date.toDate());
        GregorianChronology calendar = GregorianChronology.getInstance();
        DateTimeField field = calendar.dayOfMonth();

        int days = 0;
        int count = 0;
        int num = field.getMaximumValue(new LocalDate(year, month, day, calendar));
        while (days < num) {
            if (cal.get(Calendar.DAY_OF_WEEK) == day) {
                count++;
            }
            date = date.plusDays(1);
            cal.setTime(date.toDate());

            days++;
        }
        return count;
    }
861877
private static int lYearDays(int year) {
        int i, sum = 348;
        for (i = 0x8000; i > 0x8; i >>= 1) {
            if ((lunarInfo[year - 1900] & i) != 0)
                sum += 1;
        }
        return (sum + leapDays(year));
    }
323988
public static int getYearDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }
834151
public static int getDaysOfMonth(Date date) {
		DateTime dt = new DateTime(date.getTime());
		return getDaysOfMonth(dt.getYear(), dt.getMonthOfYear());
	}
641384
public static int fixedFromGregorian(int year, int month, int day) {
        int yearM1 = year - 1;
        return 365 * yearM1 +
                yearM1 / 4 -
                yearM1 / 100 +
                yearM1 / 400 +
                (367 * month - 362) / 12 +
                (month <= 2 ? 0 :
                        isLeapYear(year) ? -1 :
                                -2) +
                day;
    }
1166310
@SuppressWarnings("deprecation")
	private Date getWeekOne(int year) {
		GregorianCalendar weekOne = new GregorianCalendar();
		weekOne.setFirstDayOfWeek(getFirstDayOfWeek());
		weekOne.setMinimalDaysInFirstWeek(getMinimalDaysInFirstWeek());
		weekOne.setTime(new Date(year, 0, 1));
		// can we use the week of 1/1/year as week one?
		int dow = weekOne.get(DAY_OF_WEEK);
		if (dow < weekOne.getFirstDayOfWeek()) dow += 7;
		int eow = weekOne.getFirstDayOfWeek() + 7;
		if ((eow - dow) < weekOne.getMinimalDaysInFirstWeek()) {
			// nope, week one is the following week
			weekOne.add(DATE, 7);
		}
		weekOne.set(DAY_OF_WEEK, weekOne.getFirstDayOfWeek());
		return weekOne.getTime();
	}
1200911
function getWhatYear (date, year, month) {
  var number
  date = toStringDate(date)
  if (baseExports.isDate(date)) {
    if (year) {
      number = year && !isNaN(year) ? year : 0
      date.setFullYear(_dateFullYear(date) + number)
    }
    if (month || !isNaN(month)) {
      if (month === STRING_FIRST) {
        return new Date(_dateFullYear(date), 0, 1)
      } else if (month === STRING_LAST) {
        date.setMonth(11)
        return getWhatMonth(date, 0, STRING_LAST)
      } else {
        date.setMonth(month)
      }
    }
  }
  return date
}
1332688
function (year) {
			var daysCount = 0;
			for (var i = 1; i <= 12; i++) {
				daysCount += this.daysInMonth(year, i);
			}
			return daysCount;
		}
1369342
private static int getDayOfYear(int cycleNumber, int dayOfCycle, int yearInCycle) {
        Integer[] cycles = getAdjustedCycle(cycleNumber);

        if (dayOfCycle > 0) {
            return dayOfCycle - cycles[yearInCycle].intValue();
        } else {
            return cycles[yearInCycle].intValue() + dayOfCycle;
        }
    }
475428
int getDaysInYearMonth(int year, int month) {
        if (month == 12 && isLeapYear(year)) {
            return LONG_MONTH_LENGTH;
        }
        return (--month % 2 == 0 ? LONG_MONTH_LENGTH : SHORT_MONTH_LENGTH);
    }
145338
private Date[] getAfterDays(int year, int month) {
        Calendar cal = Calendar.getInstance();
        cal.set(Calendar.YEAR, year);
        cal.set(Calendar.MONTH, month);
        int dayNum = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        cal.set(year, month, dayNum);
        int afterDayNum = 7 - getDayIndex(year, month, dayNum);
        Date[] date = new Date[afterDayNum];
        if (afterDayNum > 0)

            for (int i = 0; i < afterDayNum; i++) {
                cal.add(Calendar.DAY_OF_MONTH, 1);
                date[i] = cal.getTime();
            }

        return date;
    }
523569
public int getEraYear(final Calendar cal) {
        ArgUtils.notNull(cal, "cal");
        
        final Calendar startCal = Calendar.getInstance(TimeZone.getTimeZone("GMT-00:00"));
        startCal.setTime(startDate);
        
        final int diff = cal.get(Calendar.YEAR) - startCal.get(Calendar.YEAR) + 1;
        return diff;
        
    }
1145876
@Override
    protected PlainDate getDate0(int year) {

        int month = this.getMonthValue();
        int ref = GregorianMath.getDayOfWeek(year, month, this.dayOfMonth);
        PlainDate result = PlainDate.of(year, month, this.dayOfMonth);

        if (ref == this.dayOfWeek) {
            return result;
        }

        int delta = (ref - this.dayOfWeek);
        int sgn = -1;

        if (this.after) {
            delta = -delta;
            sgn = 1;
        }

        if (delta < 0) {
            delta += 7;
        }

        return result.plus(delta * sgn, DAYS);

    }
1229600
def gday_of_year(self):
        """"""
        return (self.date - dt.date(self.date.year, 1, 1)).days