diff --git a/seasonal_clock/times.py b/seasonal_clock/times.py index 904d5ae..2608da6 100644 --- a/seasonal_clock/times.py +++ b/seasonal_clock/times.py @@ -92,31 +92,49 @@ def collect_day_parts( return day_parts +def get_rahukaalam_times( + observer: LocationInfo, + date: datetime, + surrounding_days: bool = False +) -> List[Tuple[datetime, datetime]]: + """Get today’s Răhukăla times""" + + if surrounding_days: + yesterday = date - timedelta(days=1) + tomorrow = date + timedelta(days=1) + dates = [yesterday, date, tomorrow] + else: + dates = [date] + + times: List[Tuple[datetime, datetime]] = [] + + for day in dates: + try: + daytime_rahukaala = sun.rahukaalam(observer, date=day, daytime=True) + except ValueError: + pass + else: + times.append(daytime_rahukaala) + + try: + night_rahukaala = sun.rahukaalam(observer, date=day, daytime=False) + except ValueError: + pass + else: + times.append(night_rahukaala) + + times.sort(key=lambda items: items[0]) + + return times + + def get_rahukaalam( observer: LocationInfo, date: datetime ) -> Tuple[Optional[bool], datetime]: """Get the time of the next Rāhukāla or, if we are in the middle of one, the time of its end""" - yesterday = date - timedelta(days=1) - tomorrow = date + timedelta(days=1) - times: List[Tuple[datetime, datetime]] = [] + times = get_rahukaalam_times(observer, date, surrounding_days=True) - for day in (yesterday, date, tomorrow): - try: - daytime_rahukaalam = sun.rahukaalam(observer, date=day, daytime=False) - except ValueError: - pass - else: - times.append(daytime_rahukaalam) - - try: - night_rahukaalam = sun.rahukaalam(observer, date=day, daytime=True) - except ValueError: - pass - else: - times.append(night_rahukaalam) - - times.sort(key=lambda items: items[0]) active: bool = False next_time: Optional[datetime] = None