ad TIMEZONE and more

This commit is contained in:
2026-02-09 12:31:06 +01:00
parent efa7533179
commit a94ec11c80
5 changed files with 60 additions and 76 deletions

View File

@@ -291,11 +291,15 @@ def run_scheduled_notifications(db: "Session"):
Schedule:
- Thursday at 12:00: Presence reminder for next week
- Friday at 12:00: Weekly parking summary
- Daily at user's preferred time: Daily parking reminder (Mon-Fri)
- Daily at user's preferred time: Daily parking reminder (Only on open days)
"""
from database.models import User
from database.models import User, OfficeWeeklyClosingDay, OfficeClosingDay
from zoneinfo import ZoneInfo
now = datetime.now()
# Use configured timezone
tz = ZoneInfo(config.TIMEZONE)
now = datetime.now(tz)
current_hour = now.hour
current_minute = now.minute
current_weekday = now.weekday() # 0=Monday, 6=Sunday
@@ -309,9 +313,39 @@ def run_scheduled_notifications(db: "Session"):
next_week = get_next_week_dates(today_date)
send_presence_reminder(user, next_week, db)
# Daily parking reminder at user's preferred time (working days only)
if current_weekday < 5: # Monday to Friday
user_hour = user.notify_daily_parking_hour or 8
user_minute = user.notify_daily_parking_minute or 0
if current_hour == user_hour and abs(current_minute - user_minute) < 5:
# Daily parking reminder at user's preferred time
user_hour = user.notify_daily_parking_hour or 8
user_minute = user.notify_daily_parking_minute or 0
# Check if it's the right time for this user
if current_hour == user_hour and abs(current_minute - user_minute) < 5:
# Check if Office is OPEN today
is_office_open = True
if user.office:
# Check weekly closing days (e.g. Sat/Sun)
# Note: WeekDay enum matches python weekday (0=Mon)
weekly_closed = db.query(OfficeWeeklyClosingDay).filter(
OfficeWeeklyClosingDay.office_id == user.office_id,
OfficeWeeklyClosingDay.weekday == current_weekday
).first()
if weekly_closed:
is_office_open = False
# Check specific closing days (Holidays)
if is_office_open:
specific_closed = db.query(OfficeClosingDay).filter(
OfficeClosingDay.office_id == user.office_id,
OfficeClosingDay.date == today_date
).first()
if specific_closed:
is_office_open = False
else:
# Fallback if no office assigned: default to Mon-Fri open
if current_weekday >= 5:
is_office_open = False
if is_office_open:
send_daily_parking_reminder(user, now, db)