Esempio n. 1
0
    def test_using_tzinfo(self):
        day = datetime.date(2018, 9, 8)
        timezone_str = "America/New_York"
        timezone = pytz.timezone(timezone_str)
        location_tz_str = Location(
            name="New York",
            latitude=NYC_LAT,
            longitude=NYC_LNG,
            timezone=timezone_str,
            diaspora=True,
        )
        location = Location(
            name="New York",
            latitude=NYC_LAT,
            longitude=NYC_LNG,
            timezone=timezone,
            diaspora=True,
        )

        compare_times(
            Zmanim(date=day,
                   location=location_tz_str).zmanim["first_stars"].time(),
            datetime.time(19, 45))

        compare_times(
            Zmanim(date=day, location=location).zmanim["first_stars"].time(),
            datetime.time(19, 45))
Esempio n. 2
0
 def test_erev_shabbat_hag(self, now, offset, erev_shabbat_chag):
     location_tz_str = Location(
         name="New York",
         latitude=NYC_LAT,
         longitude=NYC_LNG,
         timezone="America/New_York",
         diaspora=True,
     )
     # Use a constant offset for Havdalah for unit test stability.
     zmanim = Zmanim(date=now, location=location_tz_str, havdalah_offset=offset)
     assert zmanim.erev_shabbat_chag == erev_shabbat_chag
Esempio n. 3
0
    def test_using_tzinfo(self):
        day = datetime.date(2018, 9, 8)
        timezone_str = "America/New_York"
        timezone = tz.gettz(timezone_str)
        location_tz_str = Location(name="New York",
                                   latitude=NYC_LAT,
                                   longitude=NYC_LNG,
                                   timezone=timezone_str,
                                   diaspora=True)
        location = Location(name="New York",
                            latitude=NYC_LAT,
                            longitude=NYC_LNG,
                            timezone=timezone,
                            diaspora=True)

        assert (Zmanim(date=day,
                       location=location_tz_str).zmanim["first_stars"].time()
                == datetime.time(19, 48))

        assert (Zmanim(
            date=day,
            location=location).zmanim["first_stars"].time() == datetime.time(
                19, 48))
Esempio n. 4
0
    def __init__(
        self,
        date=dt.datetime.now(),
        location=Location(),
        hebrew=True,
        candle_lighting_offset=18,
        havdalah_offset=0,
    ):
        """
        Initialize the Zmanim object.

        As the timezone is expected to be part of the location object, any
        tzinfo passed along is discarded. Essentially making the datetime
        object non-timezone aware.

        The time zone information is appended to the date received based on the
        location object. After which it is transformed to UTC for all internal
        calculations.
        """
        self.location = location
        self.hebrew = hebrew
        self.candle_lighting_offset = candle_lighting_offset
        self.havdalah_offset = havdalah_offset

        # If a non-timezone aware date is received, use timezone from location
        # to make it timezone aware and change to UTC for calculations.

        # If timezone aware is received as date, we expect it to match the
        # timezone specified by location, so it can be overridden and changed
        # to UTC for calculations as above.
        if isinstance(date, dt.datetime):
            _LOGGER.debug("Date input is of type datetime: %r", date)
            self.date = date.date()
            self.time = date.replace(tzinfo=None)
        elif isinstance(date, dt.date):
            _LOGGER.debug("Date input is of type date: %r", date)
            self.date = date
            self.time = dt.datetime.now()
        else:
            raise TypeError

        _LOGGER.debug("Resetting timezone to UTC for calculations")
        self.time = location.timezone.localize(self.time).astimezone(pytz.utc)

        if _USE_ASTRAL:
            self.astral_observer = astral.Observer(
                latitude=self.location.latitude, longitude=self.location.longitude
            )
            self.astral_sun = astral.sun.sun(self.astral_observer, self.date)
Esempio n. 5
0
 def test_havdalah(self, now, offset, havdalah, melacha_assur):
     location_tz_str = Location(
         name="New York",
         latitude=NYC_LAT,
         longitude=NYC_LNG,
         timezone="America/New_York",
         diaspora=True,
     )
     # Use a constant offset for Havdalah for unit test stability.
     zmanim = Zmanim(date=now, location=location_tz_str, havdalah_offset=offset)
     actual = zmanim.havdalah
     if actual is not None:
         actual = actual.replace(tzinfo=None)
     compare_dates(actual, havdalah)
     assert zmanim.issur_melacha_in_effect == melacha_assur
Esempio n. 6
0
 def test_candle_lighting(self, now, offset, candle_lighting,
                          melacha_assur):
     location_tz_str = Location(name="New York",
                                latitude=NYC_LAT,
                                longitude=NYC_LNG,
                                timezone="America/New_York",
                                diaspora=True)
     # Use a constant offset for Havdalah for unit test stability.
     zmanim = Zmanim(date=now,
                     location=location_tz_str,
                     candle_lighting_offset=offset,
                     havdalah_offset=42)
     actual = zmanim.candle_lighting
     if actual is not None:
         actual = actual.replace(tzinfo=None)
     assert actual == candle_lighting
     assert zmanim.issur_melacha_in_effect == melacha_assur
Esempio n. 7
0
    def __init__(self,
                 date=dt.datetime.now(),
                 location=Location(),
                 hebrew=True,
                 candle_lighting_offset=18,
                 havdalah_offset=0):
        """Initialize the Zmanim object."""
        self.location = location
        self.hebrew = hebrew
        self.candle_lighting_offset = candle_lighting_offset
        self.havdalah_offset = havdalah_offset

        if isinstance(date, dt.datetime):
            self.date = date.date()
            self.time = date.replace(tzinfo=location.timezone)
        elif isinstance(date, dt.date):
            self.date = date
            self.time = dt.datetime.now().replace(tzinfo=location.timezone)
        else:
            raise TypeError