예제 #1
0
def parse_jewish_date(string):
    match = re.match(pattern=r'^(?P<day>\d{1,2})[-\/,\.](?P<month>\d{1,2})[-\/,\.](?P<year>\d{4})$', string=string)
    if not match:
        raise argparse.ArgumentTypeError("%r is not a valid jewish date" % string)
    else:
        try:
            return JDate(year=int(match.group('year')),
                         month=int(match.group('month')),
                         day=int(match.group('day')))
        except ValueError as ve:
            msg = '"{}" is not a valid jewish date as {}'.format(string, ve)
            raise argparse.ArgumentTypeError(msg)
예제 #2
0
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)
예제 #3
0
 def itermonthdates(year, month):
     """
     Return an iterator for one month. The iterator will yield datetime.date
     values and will always iterate through complete weeks, so it will yield
     dates outside the specified month.
     """
     date = JDate(year, month, 1)
     # Go back to the beginning of the week
     days = date.getdow() % 7
     date -= days
     oneday = 1
     while True:
         yield date
         try:
             date += oneday
         except OverflowError:
             # Adding one day could fail after datetime.MAXYEAR
             break
         if date.month != month and date.getdow() == 0:
             break
예제 #4
0
def weekday(year, mnth, day):
    """Return weekday (0-6 ~ Sun-Shabbos) for year (5776-...), month (1-12), day (1-30)."""
    return JDate(year, mnth, day).getdow()
예제 #5
0
def ellul(jd, israel):
    praklist = ()
    jyear = jd.year
    jday = jd.day
    # The first day of Ellul.
    # The year/month/day/ordinal constructor is used for efficiency.
    day1 = JDate(jyear, 6, 1, jd.ordinal - jd.day + 1)
    day1dow = day1.getdow()
    shabbos1day = 1 if day1dow == 6 else ((6 - (day1dow + 6) % 6) + 1)
    shabbos1date = JDate(jyear, 6, shabbos1day, day1.ordinal + shabbos1day - 1)
    # Which shabbos in Ellul are we working out now?
    cshb = 1 if jday == shabbos1day else int((jday - shabbos1day) / 7) + 1

    perek1 = get_first_perek(shabbos1date, israel)
    if perek1 == 1:
        if cshb == 1:
            praklist = 1,
        elif cshb == 2:
            praklist = 2,
        elif cshb == 3:
            praklist = 3, 4
        elif cshb == 4:
            praklist = 5, 6
    elif perek1 == 2:
        if cshb == 1:
            praklist = 2,
        elif cshb == 2:
            praklist = 3,
        elif cshb == 3:
            praklist = 4,
        elif cshb == 4:
            praklist = 5, 6
    elif perek1 == 3:
        if cshb == 1:
            praklist = 3,
        elif cshb == 2:
            praklist = 4,
        elif cshb == 3:
            praklist = 5,
        elif cshb == 4:
            praklist = 6,
    elif perek1 == 4:
        # This can only happen in Chutz La'aretz
        if cshb == 1:
            praklist = 4, 5
        elif cshb == 2:
            praklist = 6, 1
        elif cshb == 3:
            praklist = 2, 3
        elif cshb == 4:
            praklist = 4, 5, 6
    elif perek1 == 5:
        if cshb == 1:
            praklist = 5, 6
        elif cshb == 2:
            praklist = 1, 2
        elif cshb == 3:
            praklist = 3, 4
        elif cshb == 4:
            praklist = 5, 6
    elif perek1 == 6:
        if cshb == 1:
            praklist = 6,
        elif cshb == 2:
            praklist = 1, 2
        elif cshb == 3:
            praklist = 3, 4
        elif cshb == 4:
            praklist = 5, 6
    return praklist