def is_asur_bemelaha(dt_: dt, lat: float, lng: float, elevation: float) -> BooleanResp: # todo add tzeis option tz = get_tz(lat, lng) is_israel = not is_diaspora(tz) location = GeoLocation('', lat, lng, tz, elevation) calendar = ZmanimCalendar(geo_location=location, date=dt_.date()) dt_ = dt_.astimezone(pytz.timezone(tz)) resp = calendar.is_assur_bemelacha(current_time=dt_, in_israel=is_israel) return BooleanResp(result=resp)
def get_omer_time(user_data: UserData) -> Optional[str]: tz_name = TimezoneFinder().timezone_at(lat=user_data.latitude, lng=user_data.longitude) location = GeoLocation('', user_data.latitude, user_data.longitude, time_zone=tz_name) calendar = ZmanimCalendar(60, geo_location=location, date=date.today()) jcalendar = JewishCalendar.from_date(date.today()) omer_day = jcalendar.day_of_omer() if not omer_day: return if jcalendar.is_assur_bemelacha( ) and jcalendar.is_tomorrow_assur_bemelacha(): return elif jcalendar.is_tomorrow_assur_bemelacha(): omer_time = calendar.candle_lighting() else: omer_time = calendar.tzais() if isinstance(omer_time, dt): return omer_time.isoformat()
def get_zmanim(date_: date, lat: float, lng: float, elevation: float, settings: ZmanimRequest) -> ZmanimResponse: tz = get_tz(lat, lng) jewish_date = JewishDate(date_).jewish_date jewish_date = f'{jewish_date[0]}-{jewish_date[1]}-{jewish_date[2]}' location = GeoLocation('', lat, lng, tz, elevation) calendar = ZmanimCalendar(geo_location=location, date=date_) zmanim = _calculate_zmanim(calendar, settings) settings = Settings(date=date_, coordinates=(lat, lng), elevation=elevation, jewish_date=jewish_date) return ZmanimResponse(settings=settings, **zmanim)
async def get_zmanim(lang: str, date: Date, lat: float, lng: float, elevation: float, settings: ZmanimSettingsModel) -> dict: # cl? _ = get_translator(lang) tz = get_tz(lat, lng) location = GeoLocation('', lat, lng, tz, elevation) calendar = ZmanimCalendar(geo_location=location, date=date) zmanim = _calculate_zmanim(calendar, settings) return zmanim raw_data = await get_calendar_data(tz, date, lat, lng) zmanim_data: dict = raw_data['zmanim'] # select only needed zmanim zmanim_data = {k: v for k, v in zmanim_data.items() if settings[k]} # translate zmanim zmanim_data = {_(txt.zmanim_names[k]): v for k, v in zmanim_data.items()} return zmanim_data
def test_mincha_ketana(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) self.assertEqual(calendar.mincha_ketana().replace(microsecond=0).isoformat(), "2017-10-17T15:55:37-04:00")
def test_sof_zman_tfila(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) day_start = calendar.sunrise_offset_by_degrees(96) day_end = calendar.sunset_offset_by_degrees(96) self.assertEqual(calendar.sof_zman_tfila(day_start, day_end).replace(microsecond=0).isoformat(), "2017-10-17T10:42:05-04:00")
def test_alos_72(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) self.assertEqual(calendar.alos_72().replace(microsecond=0).isoformat(), "2017-10-17T05:57:51-04:00")
def test_alos_with_custom_degree_offset(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) self.assertEqual(calendar.alos({'degrees': 19.8}).replace(microsecond=0).isoformat(), "2017-10-17T05:30:07-04:00")
def test_assur_bemelacha_on_first_of_single_issur_melacha_in_israel(self): date = '2018-03-31' # first day of pesach calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=parser.parse(date)) self.assertTrue(calendar.is_assur_bemelacha(calendar.tzais() - timedelta(seconds=2), in_israel=True)) self.assertFalse(calendar.is_assur_bemelacha(calendar.tzais() + timedelta(seconds=2), in_israel=True))
def test_assur_bemelacha_prior_to_issur_melacha_day(self): date = '2017-10-20' calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=parser.parse(date)) self.assertFalse(calendar.is_assur_bemelacha(calendar.shkia() - timedelta(seconds=2))) self.assertTrue(calendar.is_assur_bemelacha(calendar.tzais() - timedelta(seconds=2))) self.assertTrue(calendar.is_assur_bemelacha(calendar.tzais() + timedelta(seconds=2)))
def test_alos_with_custom_minute_offset_using_elevation(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) calendar.use_elevation = True self.assertEqual(calendar.alos({'offset': 60}).replace(microsecond=0).isoformat(), "2017-10-17T06:09:11-04:00")
def test_alos_using_elevation(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) calendar.use_elevation = True self.assertEqual(calendar.alos().replace(microsecond=0).isoformat(), "2017-10-17T05:49:30-04:00")
def test_tzais_with_custom_temporal_minute_offset_using_elevation(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) calendar.use_elevation = True self.assertEqual(calendar.tzais({'zmanis_offset': 90}).replace(microsecond=0).isoformat(), "2017-10-17T19:37:49-04:00")
def test_tzais_with_custom_degree_offset_using_elevation(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) calendar.use_elevation = True self.assertEqual(calendar.tzais({'degrees': 19.8}).replace(microsecond=0).isoformat(), "2017-10-17T19:53:34-04:00")
def test_shkia(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) self.assertEqual(calendar.shkia(), calendar.sea_level_sunset())
def test_shaah_zmanis_by_degrees_and_offset_with_both_degrees_and_offset_using_elevation(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) calendar.use_elevation = True self.assertEqual(int(calendar.shaah_zmanis_by_degrees_and_offset(6, 72)), 4314499)
def test_assur_bemelacha_for_issur_melacha_day_with_custom_tzais_rule(self): date = '2017-10-21' calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=parser.parse(date)) tzais = calendar.tzais({'degrees': 11.5}) self.assertTrue(calendar.is_assur_bemelacha(tzais - timedelta(seconds=2), {'degrees': 11.5})) self.assertFalse(calendar.is_assur_bemelacha(tzais + timedelta(seconds=2), {'degrees': 11.5}))
def test_sof_zman_shma_using_elevation(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) calendar.use_elevation = True day_start = calendar.sunrise_offset_by_degrees(96) day_end = calendar.sunset_offset_by_degrees(96) self.assertEqual(calendar.sof_zman_shma(day_start, day_end).replace(microsecond=0).isoformat(), "2017-10-17T09:42:10-04:00")
def test_assur_bemelacha_on_first_of_two_issur_melacha_days(self): date = '2018-03-31' # first day of pesach calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=parser.parse(date)) self.assertTrue(calendar.is_assur_bemelacha(calendar.shkia() - timedelta(seconds=2))) self.assertTrue(calendar.is_assur_bemelacha(calendar.tzais() - timedelta(seconds=2))) self.assertTrue(calendar.is_assur_bemelacha(calendar.tzais() + timedelta(seconds=2)))
def test_sof_zman_tfila_gra_using_elevation(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) calendar.use_elevation = True self.assertEqual(calendar.sof_zman_tfila_gra().replace(microsecond=0).isoformat(), "2017-10-17T10:51:00-04:00")
def test_assur_bemelacha_on_first_of_two_issur_melacha_days_in_israel(self): date = '2018-05-19' # Shabbos before Shavuos calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=parser.parse(date)) self.assertTrue(calendar.is_assur_bemelacha(calendar.tzais() - timedelta(seconds=2), in_israel=True)) self.assertTrue(calendar.is_assur_bemelacha(calendar.tzais() + timedelta(seconds=2), in_israel=True))
def test_mincha_gedola_using_elevation(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) calendar.use_elevation = True self.assertEqual(calendar.mincha_gedola().replace(microsecond=0).isoformat(), "2017-10-17T13:09:38-04:00")
def test_alos_with_custom_temporal_minute_offset(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) self.assertEqual(calendar.alos({'zmanis_offset': 90}).replace(microsecond=0).isoformat(), "2017-10-17T05:46:50-04:00")
def test_candle_lighting_using_elevation(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) calendar.use_elevation = True self.assertEqual(calendar.candle_lighting().replace(microsecond=0).isoformat(), "2017-10-17T17:55:58-04:00")
def test_chatzos(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) self.assertEqual(calendar.chatzos().replace(microsecond=0).isoformat(), "2017-10-17T12:41:55-04:00")
def test_shaah_zmanis_using_elevation(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) calendar.use_elevation = True day_start = calendar.sunrise_offset_by_degrees(96) day_end = calendar.sunset_offset_by_degrees(96) self.assertEqual(int(calendar.shaah_zmanis(day_start, day_end)), 3594499)
def test_sof_zman_tfila_mga(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) self.assertEqual(calendar.sof_zman_tfila_mga().replace(microsecond=0).isoformat(), "2017-10-17T10:27:14-04:00")
def test_tzais_with_custom_minute_offset(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) self.assertEqual(calendar.tzais({'offset': 60}).replace(microsecond=0).isoformat(), "2017-10-17T19:13:58-04:00")
def test_plag_hamincha(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) self.assertEqual(calendar.plag_hamincha().replace(microsecond=0).isoformat(), "2017-10-17T17:04:48-04:00")
def test_shaah_zmanis_mga_using_elevation(self): calendar = ZmanimCalendar(geo_location=test_helper.lakewood(), date=date(2017, 10, 17)) calendar.use_elevation = True self.assertEqual(int(calendar.shaah_zmanis_mga()), 4047251)