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
Esempio n. 2
0
def monthrange(year, mnth):
    """Return weekday (0-6 ~ Sun-Shabbos) and number of days (29-30) for
       year, mnth."""
    if not 1 <= mnth <= 13:
        raise IllegalMonthError(mnth)
    day1 = weekday(year, mnth, 1)
    ndays = JDate.days_in_jmonth(year, mnth)
    return day1, ndays
def julian_to_jdate(julian_date):
    julian_date = trunc(julian_date) + 0.5
    count = trunc(((julian_date - EPOCH_JDATE) * 98496.0) / 35975351.0)
    year = count - 1
    i = count
    while julian_date >= jdate_to_julian(JDate(i, 7, 1)):
        i += 1
        year += 1

    if julian_date < jdate_to_julian(JDate(year, 1, 1)):
        first = 7
    else:
        first = 1

    month = i = first
    while julian_date > jdate_to_julian(
            JDate(year, i, JDate.days_in_jmonth(year, i))):
        i += 1
        month += 1

    day = int(julian_date - jdate_to_julian(JDate(year, month, 1))) + 1
    return JDate(year, month, day)
Esempio n. 4
0
def getdailyinfo(jd, location, hebrew):
    from jcal.jdate import JDate
    import jcal.utils
    from jcal.molad import Molad
    from jcal.hourminute import HourMinute
    from jcal.sedra import Sedra
    from jcal.dafyomi import Dafyomi
    from jcal.pirkeiavos import get_pirkeiavos

    infos = OrderedDict()
    sedras = Sedra.get_sedra(jd, location.israel)
    holidays = jd.get_holidays(location.israel)

    if hebrew:
        infos['תאריך'] = jd.tostring_heb()
        for h in holidays:
            htext = h.heb
            if 'מברכים' in htext:
                next_month = jd.add_days(12)
                htext += '- חודש ' + utils.proper_jmonth_name(next_month.year, next_month.month, hebrew=True)
                htext += '\nהמולד: ' + Molad.molad_string_heb(next_month.month, next_month.year)
                dim = JDate.days_in_jmonth(jd.year, jd.month)
                dow = dim - jd.day - (1 if dim == 30 else 0)
                htext += '\nראש חודש: ' + utils.dow_heb[dow]
                if dim == 30:
                    htext += ", " + utils.dow_heb[(dow + 1) % 7]
            infos[htext] = ''
        if jd.has_eiruv_tavshilin(location.israel):
            infos['עירוב תבשילין'] = ''
        if jd.has_candle_lighting():
            infos['הדלקת נרות'] = jd.get_candle_lighting(location)
        infos['פרשת השבוע'] = ' - '.join([s[1] for s in sedras])
        dy = Dafyomi.tostring_heb(jd)
        if dy:
            infos['דף יומי'] = Dafyomi.tostring_heb(jd)
        if jd.getdow() == 6:
            prakim = get_pirkeiavos(jd, location.israel)
            if prakim:
                infos['פרקי אבות'] = ' פרק' + ' ופרק '.join([utils.jsd[p - 1] for p in prakim])
    else:
        infos["Date"] = jd.tostring()
        infos['Parshas Hashavua'] = ' - '.join([s[0] for s in sedras])
        for h in holidays:
            htext = h.eng
            if 'Mevarchim' in htext:
                next_month = jd.add_days(12)
                htext += '- Chodesh ' + utils.proper_jmonth_name(next_month.year, next_month.month)
                htext += '\nThe Molad: ' + Molad.molad_string_heb(next_month.month, next_month.year)
                dim = JDate.days_in_jmonth(jd.year, jd.month)
                dow = dim - jd.getdow() - (1 if dim == 30 else 0)
                htext += '\nRosh Chodesh: ' + utils.dow_heb[dow]
                if dim == 30:
                    htext += ", " + utils.dow_eng[(dow + 1) % 7]
            infos[htext] = ''
        if jd.has_eiruv_tavshilin(location.israel):
            infos['Eruv Tavshilin'] = ''
        if jd.has_candle_lighting():
            infos['Candle Lighting'] = jd.get_candle_lighting(location)
        infos['Daf Yomi'] = Dafyomi.tostring(jd)
        if jd.getdow() == 6:
            prakim = get_pirkeiavos(jd, location.israel)
            if prakim:
                infos['Pirkei Avos'] = ' and '.join([utils.to_suffixed(p) + ' Perek' for p in prakim])
    return infos