number of leap month or zero if no leap year
353453
final int getLeapMonth(
        int cycle,
        int yearOfCycle
    ) {
        int[] leapMonths = this.getLeapMonths();
        int elapsedYears = (cycle - 1) * 60 + yearOfCycle - 1;
        int index = 2 * ((elapsedYears - leapMonths[0]) / 3); // first lower bound estimation
        int lm = 0;

        while ((index < leapMonths.length)) {
            int test = leapMonths[index];

            if (test < elapsedYears) {
                index += Math.max(2 * ((elapsedYears - test) / 3), 2);
            } else if (test > elapsedYears) {
                break;
            } else { // test == elapsedYears
                lm = leapMonths[index + 1];
                break;
            }
        }

        return lm;
    }
1351784
private static int daysInMonth(int year, int month) {
    assert month >= FIRST_MONTH && month <= LAST_MONTH;
    int d = DAYS_IN_MONTH[month - 1];
    if (month == FEBRUARY && isLeapYear(year)) d++;
    return d;
  }
330137
private static boolean isIMMMonth(final Calendar cal) {
        final int month = cal.get(MONTH);

        switch (month) {
        case MARCH:
        case JUNE:
        case SEPTEMBER:
        case DECEMBER:
            return true;
        default:
            return false;
        }
    }
1179216
def as_float(self):
        '''
        '''
        if not self.year:
            return None
        out = float(self.year.replace('?', '9'))
        if self.month:
            # TODO: we are assuming months are of equal length
            out += float(self.month.replace('?', '0')) / 12.0
            if self.day:
                out += float(self.day.replace('?', '0')) / 365.0
        return out
1198042
def _seconds_to_days(cls, val, **kwargs):
        '''
        
        '''
        zero_value = kwargs.get('zero_value', 0)
        if val is not None:
            if val == zero_value:
                return 0
            return val / 86400
        else:
            return 'Not Defined'
308401
def leap(year, method=None):
    '''
    
    '''

    method = method or 'equinox'

    if year in (3, 7, 11):
        return True
    elif year < 15:
        return False

    if method in (4, 'continuous') or (year <= 16 and method in (128, 'madler', 4, 'continuous')):
        return year % 4 == 3

    elif method in (100, 'romme'):
        return (year % 4 == 0 and year % 100 != 0) or year % 400 == 0

    elif method in (128, 'madler'):
        return year % 4 == 0 and year % 128 != 0

    elif method == 'equinox':
        # Is equinox on 366th day after (year, 1, 1)
        startjd = to_jd(year, 1, 1, method='equinox')
        if premier_da_la_annee(startjd + 367) - startjd == 366.0:
            return True
    else:
        raise ValueError("Unknown leap year method. Try: continuous, romme, madler or equinox")

    return False
42659
public static function numberOfDaysInMonth($month = 0, $year = 0)
    {
        if ($month < 1 or $month > 12) {
            return 0;
        }

        if (!is_numeric($year) or strlen($year) != 4) {
            $year = date('Y');
        }

        if ($month == 2) {
            if ($year % 400 == 0 or ($year % 4 == 0 and $year % 100 != 0)) {
                return 29;
            }
        }

        $days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

        return $days_in_month[$month - 1];
    }
469857
def calculation(atom, base)
      initial = base.month + atom
      if initial <= 0
        month = base.month + atom

        if (initial % 12).zero?
          year = base.year + (initial / 12) - 1
          month = 12
        else
          year = base.year + (initial / 12).floor
          month = 12 + initial > 0 ? (12 + initial) : (12 + (initial % -12))
        end
      else
        month = initial <= 12 ? initial : (initial % 12)
        month = 12 if month.zero?
        year = initial <= 12 ? base.year : base.year + (initial / 12).to_i
      end

      (::Time.utc(year, month) - ::Time.utc(base.year, base.month)) / atom
    end
1223143
private static BigInteger computeDays(BigInteger months, int refYear, int refMonth) {
    switch (months.signum()) {
    case 0:
      return BigInteger.valueOf(0);
    case -1:
      return computeDays(months.negate(), refYear, refMonth).negate();
    }
    // Complete cycle of Gregorian calendar is 400 years
    BigInteger[] tem = months.divideAndRemainder(BigInteger.valueOf(400*12));
    --refMonth; // use 0 base to match Java
    int total = 0;
    for (int rem = tem[1].intValue(); rem > 0; rem--) {
      total += daysInMonth(refYear, refMonth);
      if (++refMonth == 12) {
        refMonth = 0;
        refYear++;
      }
    }
    // In the Gregorian calendar, there are 97 (= 100 + 4 - 1) leap years every 400 years.
    return tem[0].multiply(BigInteger.valueOf(365*400 + 97)).add(BigInteger.valueOf(total));
  }
539524
def W(self):
    ""
    # Algorithm from http://www.personal.ecu.edu/mccartyr/ISOwdALG.txt
    week_number = None
    jan1_weekday = self.data.replace(month=1, day=1).weekday() + 1
    weekday = self.data.weekday() + 1
    day_of_year = self.z()
    if day_of_year <= (8 - jan1_weekday) and jan1_weekday > 4:
      if jan1_weekday == 5 or (jan1_weekday == 6 and calendar.isleap(self.data.year-1)):
        week_number = 53
      else:
        week_number = 52
    else:
      if calendar.isleap(self.data.year):
        i = 366
      else:
        i = 365
      if (i - day_of_year) < (4 - weekday):
        week_number = 1
      else:
        j = day_of_year + (7 - weekday) + (jan1_weekday - 1)
        week_number = j // 7
        if jan1_weekday > 4:
          week_number -= 1
    return week_number
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;
    }
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;
        }
    }
239142
function countFromTo(koyomi, from, to) {
  var blocks = koyomi.separate(from, to);
  if (!blocks) {
    return null;
  }
  var days = 0;
  days += blocks.days.reduce((x, d) => koyomi.isOpen(d) ? x + 1 : x, 0);
  days += blocks.months.reduce((x, d) => x + countMonth(koyomi, d), 0);
  days += blocks.years.reduce((x, d) => x + countYear(koyomi, d), 0);
  return days;
}
1097444
def _days_to_seconds(cls, val, **kwargs):
        '''
        
        '''
        zero_value = kwargs.get('zero_value', 0)
        if val is not None:
            if val == 0:
                return zero_value
            return val * 86400
        else:
            return 'Not Defined'
1122591
def _adjust_n_years(other, n, month, reference_day):
    """"""
    if n > 0:
        if other.month < month or (other.month == month and
                                   other.day < reference_day):
            n -= 1
    else:
        if other.month > month or (other.month == month and
                                   other.day > reference_day):
            n += 1
    return n
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;
	}
926633
private static int EquivalentYear(int year)
    {
        int day = (int) DayFromYear(year) + 4;
        day = day % 7;
        if (day < 0)
            day += 7;
        // Years and leap years on which Jan 1 is a Sunday, Monday, etc.
        if (IsLeapYear(year)) {
            switch (day) {
                case 0: return 1984;
                case 1: return 1996;
                case 2: return 1980;
                case 3: return 1992;
                case 4: return 1976;
                case 5: return 1988;
                case 6: return 1972;
            }
        } else {
            switch (day) {
                case 0: return 1978;
                case 1: return 1973;
                case 2: return 1985;
                case 3: return 1986;
                case 4: return 1981;
                case 5: return 1971;
                case 6: return 1977;
            }
        }
        // Unreachable
        throw Kit.codeBug();
    }