From b0f8daebd0100def0442304bad4a5f32d0413b0c Mon Sep 17 00:00:00 2001 From: Bruce <107087485+savdagod@users.noreply.github.com> Date: Sat, 9 Nov 2024 16:40:44 -0500 Subject: [PATCH] Update thanksgiving_day.star --- apps/thanksgivingday/thanksgiving_day.star | 33 ++++++++++++++-------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/apps/thanksgivingday/thanksgiving_day.star b/apps/thanksgivingday/thanksgiving_day.star index 7850e5da0..aa3f1979e 100644 --- a/apps/thanksgivingday/thanksgiving_day.star +++ b/apps/thanksgivingday/thanksgiving_day.star @@ -17,23 +17,32 @@ R0lGODlhIAAgAPcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA """) def main(config): + + def getthanksgivingday(year): + nov30 = time.time(year = year,month = 11,day = 30,location = timezone) + day_of_week = humanize.day_of_week(nov30) + calc = day_of_week - 4 + if calc > 0: + day = 30 - calc + else: + day = 30 - (calc + 7) + + return day + timezone = config.get("timezone") or "America/New_York" - now = time.now().in_location(timezone) + now = time.time(year = time.now().year,month = time.now().month,day = time.now().day,location = timezone) - nov30 = time.time(year = now.year,month = 11,day = 30,location = timezone) - day_of_week = humanize.day_of_week(nov30) - calc = day_of_week - 4 - if calc > 0: - day = 30 - calc - else: - day = 30 - (calc + 7) + day = getthanksgivingday(now.year) thanksgiving_day = time.time(year = now.year,month = 11,day = day,location = timezone) + if now >= thanksgiving_day: + next_year = now.year + 1 + day = getthanksgivingday(next_year) + thanksgiving_day = time.time(year = next_year,month = 11,day = day,location = timezone) + diff = thanksgiving_day - now diff_days = abs(int(diff.hours / 24)) - if now < thanksgiving_day: - days_til_thanksgiving = diff_days + 1 - else: - days_til_thanksgiving = 365 - (diff_days + 1) + days_til_thanksgiving = diff_days + return render.Root( delay = 1000,