1
Fork 0
mirror of https://github.com/wlinator/luminara.git synced 2024-10-02 22:23:13 +00:00
Lumi/lib/time.py

20 lines
596 B
Python
Raw Normal View History

2023-10-18 14:00:28 +00:00
import datetime
import pytz
def seconds_until(hours, minutes):
2024-07-17 11:47:26 +00:00
eastern_timezone = pytz.timezone("US/Eastern")
2023-10-18 14:00:28 +00:00
now = datetime.datetime.now(eastern_timezone)
# Create a datetime object for the given time in the Eastern Timezone
given_time = datetime.time(hours, minutes)
future_exec = eastern_timezone.localize(datetime.datetime.combine(now, given_time))
# If the given time is before the current time, add one day to the future execution time
if future_exec < now:
future_exec += datetime.timedelta(days=1)
return (future_exec - now).total_seconds()