def greg_to_jdate(date_or_year, month=None, day=None): """ date_or_year can be: - an instance of the built-in datetime.date/datetime.datetime class - a utils.GregorianDate namedtuple - an int representing the Gregorian year """ if _is_legal_greg_date(date_or_year, month, day): if isinstance(date_or_year, datetime.date): return JDate.fromordinal(date_or_year.toordinal()) if isinstance(date_or_year, int): y, m, d = date_or_year, month or 1, day or 1 else: y, m, d = date_or_year # unpack the utils.GregorianDate namedtuple if y > 0: return JDate.fromordinal(datetime.date(y, m, d).toordinal()) else: return julian_to_jdate(greg_to_julian(d, m, y))
def get_molad(month, year): month_adj = month - 7 if month_adj < 0: month_adj += JDate.months_in_jyear(year) total_months = int(month_adj + 235 * int((year - 1) / 19) + 12 * ((year - 1) % 19) + ((((year - 1) % 19) * 7) + 1) / 19) parts_elapsed = 204 + (793 * (total_months % 1080)) hours_elapsed = 5 + (12 * total_months) + 793 * int( total_months / 1080) + int(parts_elapsed / 1080) - 6 parts = int((parts_elapsed % 1080) + 1080 * (hours_elapsed % 24)) return dict(JDate=JDate.fromordinal((1 + (29 * int(total_months))) + int((hours_elapsed / 24))), time=HourMinute( int(hours_elapsed) % 24, int((parts % 1080) / 18)), chalakim=parts % 18)