Skip to content

Commit

Permalink
Hot-fix handle timezone issues with OH recurrence pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisJordan committed Jan 22, 2025
1 parent abf0c2f commit 8810b39
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions backend/models/office_hours/office_hours_recurrence_pattern.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from datetime import datetime

from pydantic import BaseModel
from zoneinfo import ZoneInfo
from pydantic import BaseModel, field_validator, ValidationInfo

__authors__ = ["Jade Keegan"]
__copyright__ = "Copyright 2024"
Expand All @@ -26,6 +26,23 @@ class NewOfficeHoursRecurrencePattern(BaseModel):
recur_saturday: bool
recur_sunday: bool

@field_validator("start_date", "end_date", mode="before")
@classmethod
def remove_timezone(cls, value: datetime):
if type(value) == str:
dt = datetime.fromisoformat(value.replace("Z", "+00:00"))
dt = dt.astimezone(ZoneInfo("America/New_York"))
dt = dt.replace(tzinfo=None)
return dt
return value

@field_validator("end_date")
@classmethod
def check_end_greater_than_start(cls, v: datetime, info: ValidationInfo):
if v <= info.data["start_date"]:
raise ValueError("end must be greater than start")
return v


class OfficeHoursRecurrencePattern(NewOfficeHoursRecurrencePattern):
"""
Expand Down

0 comments on commit 8810b39

Please sign in to comment.