def __init__(self, date_time, lat_lon, **kwargs): self.lat_lon = lat_lon if 'timezone' not in kwargs: print('timezone not in kwargs') self.timezone = location.get_timezone(self.lat_lon) else: self.timezone = kwargs['timezone'] self.date_time = proccess_time.proccess_datetime( date_time, timezone=self.timezone) self.sun = sun.Sun(self.date_time, self.lat_lon, timezone=self.timezone) if self.sun.is_yom(): self.night = False else: self.night = True self.greg_year = int(self.date_time.strftime('%Y')) self.greg_month = int(self.date_time.strftime('%m')) self.greg_day = int(self.date_time.strftime('%d')) self.heb_date = dates.GregorianDate( self.greg_year, self.greg_month, self.greg_day).to_heb(night=self.night) self.heb_year = self.heb_date.tuple() self.heb_month = self.heb_date.tuple()[1] self.heb_day = self.heb_date.tuple()[2]
def test_greg_sanity(self): for i in range(347998, 2460000, 117): jd = dates.JulianDay(i) conf = jd.to_greg().to_jd() if jd >= dates.GregorianDate(1, 1, 1): assert jd.day == conf.day else: assert abs(jd.day - conf.day) <= 1
def test_operator_errors(self): day = dates.GregorianDate(2016, 11, 20) for operator in [add, sub]: for value in ['Hello', '', None]: with pytest.raises(TypeError): operator(day, value) with pytest.raises(TypeError): day + (day + 1)
def iteryears(): if not request.args['date']: return render_template('years_viewer.html', hebrew_date='', years_list=[]) date = datetime.datetime.strptime(request.args['date'], '%Y-%m-%d') gregorian_date = dates.GregorianDate(date.year, date.month, date.day) hebrew_date: dates.HebrewDate = gregorian_date.to_heb() years = [] for i in range(dates.GregorianDate.today().year, dates.GregorianDate.today().year + YEARS_TO_CHECK): georgian_new_date = dates.GregorianDate(i, gregorian_date.month, gregorian_date.day) gregorian_hebrew_date = georgian_new_date.to_heb() if gregorian_hebrew_date.month == hebrew_date.month and gregorian_hebrew_date.day == hebrew_date.day: years.append(i) return render_template('years_viewer.html', hebrew_date=hebrew_date, years_list=years)
def _hebrew_year(year): """ Return the Hebrew calendar year that corresponds to 1st January of the given Gregorian calendar year. 1st January of any Gregorian calendar year, say x, always falls into the month of Tevet (10) or Shevat (11) of some Hebrew year f(x). Also, we have f(x+1) = f(x) + 1, so that any year in the Gregorian calendar always overlaps with two consecutive years in the Hebrew calendar and vice versa. """ return hebrewcal.Year(dates.GregorianDate(year, 1, 1).to_heb().year)
def get_rh(loc, lang): tz = f.get_tz_by_location(loc) tz_time = pytz.timezone(tz) now = datetime.now(tz_time) hebrew_date = dates.GregorianDate(now.year, now.month, now.day).to_heb().tuple() if hebrew_date[1] == 6: hebrew_date = (hebrew_date[0] + 1, 7, hebrew_date[2]) params = {'hebrewYear': hebrew_date[0]} chodesh = requests.get(URL, params=params) chodesh_dict = chodesh.json() if (len(chodesh_dict) == 13) and (hebrew_date[1] == 13) or \ (len(chodesh_dict) == 12) and (hebrew_date[1] == 12): chodesh_dict = chodesh_dict[0] # выбираем нисан else: chodesh_dict = chodesh_dict[hebrew_date[1]] length_of_rh = get_rh_lenght(hebrew_date) length_str = f'{length_of_rh}' if lang == 'Русский': rh = '*Рош ходеш* 🌒\n\n' \ '*Месяц:* {month}\n' \ '*Продолжительность Рош Ходеша:* {length} {length_r}\n' \ '*Рош Ходеш:* {rh}\n' \ '*Молад:* {mol}'.format( month=data.jewish_months[get_month_name(chodesh_dict)], length=length_str, length_r=data.length_r[length_str], rh=get_rh_date_and_day(hebrew_date, length_of_rh, lang), mol=get_molad(chodesh_dict, lang) ) elif lang == 'English': rh = '*Rosh Chodesh* 🌒\n\n*Month:* {month}\n' \ '*Rosh Chodesh duration:* {length} {length_r}\n' \ '*Rosh Chodesh:* {rh}\n' \ '*Molad:* {mol}'.format( month=get_month_name(chodesh_dict), length=length_str, length_r=data.length_e[length_str], rh=get_rh_date_and_day(hebrew_date, length_of_rh, lang), mol=get_molad(chodesh_dict, lang) ) return rh
def get_rh(loc, lang): tz = f.get_tz_by_location(loc) tz_time = pytz.timezone(tz) now = datetime.now(tz_time) hebrew_date = dates.GregorianDate(now.year, now.month, now.day).to_heb().tuple() # проверка на рош ашану if hebrew_date[1] == 6: hebrew_date = ( hebrew_date[0], hebrew_date[1] + 1, hebrew_date[2] ) params = {'hebrewYear': hebrew_date[0]} chodesh_dict = get_chodesh_dict(hebrew_date, params) length_of_rh = get_rh_lenght(hebrew_date) length_str = f'{length_of_rh}' if lang == 'Русский': rh = '*Рош ходеш* 🌒\n\n' \ '*Месяц:* {month}\n' \ '*Продолжительность Рош Ходеша:* {length} {length_r}\n' \ '*Рош Ходеш:* {rh}\n' \ '*Молад:* {mol}'.format( month=data.jewish_months[get_month_name(chodesh_dict)], length=length_str, length_r=data.length_r[length_str], rh=get_rh_date_and_day(hebrew_date, length_of_rh, lang), mol=get_molad(chodesh_dict, lang) ) elif lang == 'English': rh = '*Rosh Chodesh* 🌒\n\n*Month:* {month}\n' \ '*Rosh Chodesh duration:* {length} {length_r}\n' \ '*Rosh Chodesh:* {rh}\n' \ '*Molad:* {mol}'.format( month=get_month_name(chodesh_dict), length=length_str, length_r=data.length_e[length_str], rh=get_rh_date_and_day(hebrew_date, length_of_rh, lang), mol=get_molad(chodesh_dict, lang) ) return rh
def test_getparsha_string(self): for key in KNOWN_VALUES_STRINGS: assert (parshios.getparsha_string(dates.GregorianDate(*key)) == KNOWN_VALUES_STRINGS[key])
def test_getparsha(self): for key in KNOWN_VALUES: assert (parshios.getparsha(dates.GregorianDate(*key)) == KNOWN_VALUES[key])
def test_asara(self): assert holiday(dates.GregorianDate(2018, 12, 18)) == '10 of Teves'
def test_lagbaomer(self): assert holiday(dates.GregorianDate(2018, 5, 3)) == "Lag Ba'omer"
def hebrew_school_year(self): # Choosing a date that is for sure after Rosh Hashana gregorian_start_of_year_date = dates.GregorianDate( self.gregorian_school_year, 11, 16) return gregorian_start_of_year_date.to_heb().year
def test_from_greg(self): for date in KNOWN_VALUES: heb = dates.GregorianDate(*date).to_heb().tuple() assert KNOWN_VALUES[date] == heb
def date(self): return dates.GregorianDate(2017, 10, 31)