Exemplo n.º 1
0
 def __init__(self, geo_location: Optional[GeoLocation] = None, date: Optional[date] = None, calculator: Optional[AstronomicalCalculations] = None):
     if geo_location is None:
         geo_location = GeoLocation.GMT()
     if date is None:
         date = datetime.today()
     if calculator is None:
         calculator = NOAACalculator()
     self.geo_location = geo_location
     self.date = date
     self.astronomical_calculator = calculator
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
def fast(name: str, date_: date, lat: Optional[float], lng: Optional[float],
         elevation: int, havdala_opinion: HavdalaChoices) -> Fast:
    tz = get_tz(lat, lng)
    diaspora = is_diaspora(tz)
    is_9_av = True if name == 'fast_9_av' else None
    havdala_params = HAVDALA_PARAMS[havdala_opinion.name]

    data = {'moved_fast': False}

    fast_date = _get_first_day_date(name, date_, diaspora)

    # Deferred fasts
    if name in ('fast_gedalia', 'fast_17_tammuz',
                'fast_9_av') and fast_date.day_of_week == 7:
        fast_date.forward(1)
        data['moved_fast'] = True
    if name == 'fast_esther' and fast_date.day_of_week == 7:
        fast_date.forward(-2)
        data['moved_fast'] = True

    location = GeoLocation('', lat, lng, tz, elevation)
    fast_calc = ZmanimCalendar(geo_location=location,
                               date=fast_date.gregorian_date)
    if is_9_av:
        eve_calc = ZmanimCalendar(geo_location=location,
                                  date=(fast_date - 1).gregorian_date)
        data['fast_start'] = eve_calc.shkia()
        data['chatzot'] = fast_calc.chatzos()
    else:
        if fast_calc.alos():
            data['fast_start'] = fast_calc.alos()
        else:
            eve_calc = ZmanimCalendar(geo_location=location,
                                      date=(fast_date - 1).gregorian_date)
            data['fast_start'] = eve_calc.chatzos() + timedelta(hours=12)

    # calculate additional fast ending times:
    # sunset = fast_calc.shkia()
    # sba_time = (sunset + timedelta(minutes=31))
    # nvr_time = (sunset + timedelta(minutes=28))
    # ssk_time = (sunset + timedelta(minutes=25))

    data['havdala'] = fast_calc.tzais(havdala_params)

    settings = Settings(havdala_opinion=havdala_opinion,
                        coordinates=(lat, lng),
                        elevation=elevation,
                        date=date_,
                        fast_name=name)

    return Fast(settings=settings, **data)
Exemplo n.º 4
0
    def molad_as_datetime(self) -> datetime:
        m = self.molad()
        location_name = 'Jerusalem, Israel'
        latitude = 31.778  # Har Habayis latitude
        longitude = 35.2354  # Har Habayis longitude
        zone = tz.gettz('Asia/Jerusalem')

        geo = GeoLocation(location_name, latitude, longitude, zone)
        seconds = m.molad_chalakim * 10 / 3.0
        seconds, microseconds = divmod(seconds * 10**6, 10**6)
        # molad as local mean time
        time = datetime(m.gregorian_year,
                        m.gregorian_month,
                        m.gregorian_day,
                        m.molad_hours,
                        m.molad_minutes,
                        int(seconds),
                        int(microseconds),
                        tzinfo=tz.gettz('Etc/GMT-2'))
        # molad as Jerusalem standard time
        micro_offset = geo.local_mean_time_offset() * 1000
        time -= timedelta(microseconds=micro_offset)
        # molad as UTC
        return time.astimezone(tz.UTC)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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()
Exemplo n.º 8
0
 def test_local_mean_time_offset_on_center_meridian(self):
     geo = GeoLocation('Sample', 40, -75, 'America/New_York')
     self.assertEqual(geo.local_mean_time_offset(), 0)
Exemplo n.º 9
0
 def test_local_mean_time_offset_for_gmt(self):
     geo = GeoLocation.GMT()
     self.assertEqual(geo.local_mean_time_offset(), 0)
Exemplo n.º 10
0
def hooper_bay():
    return GeoLocation('Hooper Bay, Alaska',
                       61.520182,
                       -166.1740437,
                       'America/Anchorage',
                       elevation=8)
Exemplo n.º 11
0
def los_angeles():
    return GeoLocation('Los Angeles, CA',
                       34.0201613,
                       -118.6919095,
                       'America/Los_Angeles',
                       elevation=71)
Exemplo n.º 12
0
def tokyo():
    return GeoLocation('Tokyo, Japan',
                       35.6733227,
                       139.6403486,
                       'Asia/Tokyo',
                       elevation=40)
Exemplo n.º 13
0
 def test_standard_time_offset_for_standard_timezone(self):
     geo = GeoLocation.GMT()
     geo.time_zone = 'America/New_York'
     self.assertEqual(geo.standard_time_offset(), -5 * GeoLocation.HOUR_MILLIS)
Exemplo n.º 14
0
 def test_longitude_cartography_west(self):
     geo = GeoLocation.GMT()
     geo.longitude = 41, 7, 5.17296, 'W'
     self.assertEqual(geo.longitude, -41.1181036)
Exemplo n.º 15
0
 def test_longitude_numeric(self):
     geo = GeoLocation.GMT()
     geo.longitude = 23.4
     self.assertEqual(geo.longitude, 23.4)
Exemplo n.º 16
0
 def test_latitude_cartography_south(self):
     geo = GeoLocation.GMT()
     geo.latitude = 41, 7, 5.17296, 'S'
     self.assertEqual(geo.latitude, -41.1181036)
Exemplo n.º 17
0
 def test_latitude_numeric(self):
     geo = GeoLocation.GMT()
     geo.latitude = 33.3
     self.assertEqual(geo.latitude, 33.3)
Exemplo n.º 18
0
 def test_entry(time, tz):
     geo = GeoLocation('Sample', 0, 0, tz)
     return time, tz, geo.time_zone_offset_at(parser.parse(time))
Exemplo n.º 19
0
def daneborg():
    return GeoLocation('Daneborg, Greenland',
                       74.2999996,
                       -20.2420877,
                       'America/Godthab',
                       elevation=0)
Exemplo n.º 20
0
 def test_local_mean_time_offset_west_of_center_meridian(self):
     geo = GeoLocation('Sample', 40, -76.25, 'America/New_York')
     self.assertEqual(geo.local_mean_time_offset(), -1.25 * 4 * GeoLocation.MINUTE_MILLIS)
Exemplo n.º 21
0
 def test_standard_time_offset_for_gmt(self):
     geo = GeoLocation.GMT()
     self.assertEqual(geo.standard_time_offset(), 0)
Exemplo n.º 22
0
 def test_time_zone_with_string(self):
     geo = GeoLocation.GMT()
     geo.time_zone = 'America/New_York'
     self.assertTrue(geo.time_zone._filename.endswith('/America/New_York'))
Exemplo n.º 23
0
 def test_time_zone_with_timezone_object(self):
     geo = GeoLocation.GMT()
     geo.time_zone = tz.gettz('America/New_York')
     self.assertTrue(geo.time_zone._filename.endswith('/America/New_York'))
Exemplo n.º 24
0
def lakewood():
    return GeoLocation('Lakewood, NJ',
                       40.0721087,
                       -74.2400243,
                       'America/New_York',
                       elevation=15)
Exemplo n.º 25
0
def get_yom_tov(name: str, date_: date, lat: float, lng: float, elevation: int,
                cl: int, havdala_opinion: HavdalaChoices) -> YomTov:
    """
    There are different holiday dates sets:
    [Y] - one yom tov — Generic yom tov in Israel
    [Y Y] - two yom tovs — Generic yom tov in diaspora
    [Y S] - one yom tov and shabbat
    [S Y Y]
    [Y S]
    [Y Y S]
    """
    tz = get_tz(lat, lng)
    diaspora = is_diaspora(tz)
    day_1_date = _get_first_day_date(name, date_, diaspora)

    shabbat_date = None
    day_2_date = None

    eve_date = day_1_date - 1  # Y

    if (diaspora
            and not name == 'yom_kippur') or name == 'rosh_hashana':  # Y Y
        day_2_date = day_1_date + 1
        # yt_dates.append(first_day + 1)

    last_yt_date = day_2_date or day_1_date

    if day_1_date.day_of_week == 1:  # S Y Y
        # eve_date = day_1_date - 2
        shabbat_date = day_1_date - 1
    elif last_yt_date.day_of_week == 6:  # Y S / Y Y S
        shabbat_date = last_yt_date + 1

    # checks
    assert eve_date.has_candle_lighting()
    assert day_1_date.is_assur_bemelacha()
    if day_2_date:
        assert day_2_date.is_yom_tov_sheni()
        assert day_2_date.is_assur_bemelacha()

    data = {}
    shabbat_term = None

    if shabbat_date and shabbat_date < day_1_date:
        shabbat_term = 'pre_shabbat'
        data[shabbat_term] = {'date': shabbat_date.gregorian_date}

    data['day_1'] = {'date': day_1_date.gregorian_date}

    if day_2_date:
        data['day_2'] = {'date': day_2_date.gregorian_date}

    if shabbat_date and shabbat_date > last_yt_date:
        shabbat_term = 'post_shabbat'
        data[shabbat_term] = {'date': shabbat_date.gregorian_date}

    if name == 'succot':
        date_hoshana_rabba = day_1_date + 6
        data['hoshana_rabba'] = date_hoshana_rabba.gregorian_date

    # zmanim calculation
    havdala_params = HAVDALA_PARAMS[havdala_opinion.name]

    location = GeoLocation('', lat, lng, tz, elevation)

    eve_zmanim_calc = ZmanimCalendar(cl,
                                     geo_location=location,
                                     date=eve_date.gregorian_date)
    first_day_calc = ZmanimCalendar(cl,
                                    geo_location=location,
                                    date=day_1_date.gregorian_date)

    if shabbat_date:
        shabbat_eve_date = shabbat_date - 1
        eve_shabbat_calc = ZmanimCalendar(cl,
                                          geo_location=location,
                                          date=shabbat_eve_date.gregorian_date)
        shabbat_calc = ZmanimCalendar(cl,
                                      geo_location=location,
                                      date=shabbat_date.gregorian_date)
        data[shabbat_term][
            'candle_lighting'] = eve_shabbat_calc.candle_lighting()

        if shabbat_date > day_1_date:
            data[shabbat_term]['havdala'] = shabbat_calc.tzais(havdala_params)

    if shabbat_term == 'pre_shabbat':
        data['day_1']['candle_lighting'] = eve_zmanim_calc.tzais(
            havdala_params)
    else:
        data['day_1']['candle_lighting'] = eve_zmanim_calc.candle_lighting()

    if not day_2_date:

        data['day_1']['havdala'] = first_day_calc.tzais(havdala_params)
        # return resp
    else:
        second_day_calc = ZmanimCalendar(cl,
                                         geo_location=location,
                                         date=day_2_date.gregorian_date)
        data['day_2']['candle_lighting'] = first_day_calc.tzais(havdala_params)
        if not shabbat_date or shabbat_date < day_2_date:
            data['day_2']['havdala'] = second_day_calc.tzais(havdala_params)

    part_2_data = {}
    if name == 'pesach':
        part_2 = get_yom_tov('pesach_2', date_, lat, lng, elevation, cl,
                             havdala_opinion)
        part_2_data = {
            'pesach_part_2_day_1': part_2.day_1,
            'pesach_part_2_day_2': part_2.day_2,
        }

    settings = Settings(cl_offset=cl,
                        havdala_opinion=havdala_opinion,
                        coordinates=(lat, lng),
                        elevation=elevation,
                        date=date_,
                        yomtov_name=name)
    return YomTov(settings=settings, **data, **part_2_data)
Exemplo n.º 26
0
 def test_antimeridian_adjustment_for_standard_timezone(self):
     geo = GeoLocation.GMT()
     geo.time_zone = 'America/New_York'
     self.assertEqual(geo.antimeridian_adjustment(), 0)
Exemplo n.º 27
0
from zmanim.zmanim_calendar import ZmanimCalendar
from zmanim.util.geo_location import GeoLocation

location = GeoLocation(name='d',
                       latitude=34.837758,
                       longitude=32.090277,
                       time_zone='Asia/Hebron')
calendar = ZmanimCalendar(geo_location=location)

calendar.tzais()
Exemplo n.º 28
0
 def test_antimeridian_adjustment_for_westward_crossover(self):
     geo = GeoLocation.GMT()
     geo.longitude = 179
     geo.time_zone = 'Etc/GMT+12'
     self.assertEqual(geo.antimeridian_adjustment(), 1)
Exemplo n.º 29
0
 def test_antimeridian_adjustment_for_gmt(self):
     geo = GeoLocation.GMT()
     self.assertEqual(geo.antimeridian_adjustment(), 0)
Exemplo n.º 30
0
def arctic_nunavut():
    return GeoLocation('Fort Conger, NU Canada',
                       81.7449398,
                       -64.7945858,
                       'America/Toronto',
                       elevation=127)