Write a new script to calculate next Sunday's date
This commit is contained in:
parent
e2d64f82f8
commit
7843ee9cdd
2 changed files with 33 additions and 1 deletions
32
scripts/next_sunday.py
Executable file
32
scripts/next_sunday.py
Executable file
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import datetime
|
||||
import time
|
||||
import zoneinfo
|
||||
|
||||
def main():
|
||||
today = datetime.date.today()
|
||||
|
||||
current_weekday = today.weekday()
|
||||
if current_weekday == 6:
|
||||
days_to_next_sunday = 6
|
||||
else:
|
||||
days_to_next_sunday = 6 - current_weekday
|
||||
|
||||
delta = datetime.timedelta(days=days_to_next_sunday)
|
||||
|
||||
noon = datetime.time(hour=12)
|
||||
|
||||
timezone = datetime.datetime.now().astimezone().tzinfo
|
||||
next_sunday_noon = datetime.datetime.combine(
|
||||
today + delta,
|
||||
noon,
|
||||
tzinfo=timezone
|
||||
)
|
||||
|
||||
print(next_sunday_noon.isoformat())
|
||||
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue