def yeardayscalendar(self, year, width=3): """ Return the data for the specified year ready for formatting (similar to yeardatescalendar()). Entries in the week lists are day numbers. Day numbers outside this month are zero. """ months = [ self.monthdayscalendar(year, i) for i in range(7, JDate.months_in_jyear(year) + 1) ] months += [self.monthdayscalendar(year, i) for i in range(1, 7)] return [months[i:i + width] for i in range(0, len(months), width)]
def _fix_order(months, year): """ Even though the month numbers for the Jewish year start from Nissan, the year starts from Tishrei. This function takes a list of month numbers used to display a yearly calendar, ordered as month 1 in year, 2 in year etc. and replaces the number with the correct real month number for that month. So for example, if the number is 1 , meaning the first month in the year, it is replaced with 7 which is the correct month number for Tishrei. """ ly = JDate.months_in_jyear(year) # list of month numbers of this Jewish Year starting from Tishrei through Ellul. monthprog = [i for i in range(7, ly + 1)] + [i for i in range(1, 7)] return [monthprog[i - 1] for i in months]
def yeardatescalendar(self, year, width=3): """ Return the data for the specified year ready for formatting. The return value is a list of month rows. Each month row contains up to width months. Each month contains between 4 and 6 weeks and each week contains 1-7 days. Days are JDate objects. """ months = [ self.monthdatescalendar(year, i) for i in range(7, JDate.months_in_jyear(year) + 1) ] months += [self.monthdatescalendar(year, i) for i in range(1, 7)] return [months[i:i + width] for i in range(0, len(months), width)]
def jdate_to_julian(jdate): year, month, day = jdate.year, jdate.month, jdate.day months = JDate.months_in_jyear(year) jd = EPOCH_JDATE + _jdate_delay_1(year) + _jdate_delay_2(year) + day + 1 if month < 7: for mon in range(7, months + 1): jd += JDate.days_in_jmonth(year, mon) for mon in range(1, month): jd += JDate.days_in_jmonth(year, mon) else: for mon in range(7, month): jd += JDate.days_in_jmonth(year, mon) return int(jd) + 0.5
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)
def formatyear(self, theyear, width=3): """ Return a formatted year as a table of tables. """ v = [] a = v.append width = max(width, 1) a('<table border="0" cellpadding="0" cellspacing="0" class="year">') a('\n') a('<tr><th colspan="%d" class="year">%s</th></tr>' % (width, theyear)) for i in range(1, JDate.months_in_jyear(theyear) + 1, width): # months in this row months = range(i, min(i + width, 14)) months = _fix_order(months, theyear) a('<tr>') for m in months: a('<td>') a(self.formatmonth(theyear, m, withyear=False)) a('</td>') a('</tr>') a('</table>') return ''.join(v)