diff --git a/src/backend/apps/event/tasks.py b/src/backend/apps/event/tasks.py index a70acbe3f..fd8df2f67 100644 --- a/src/backend/apps/event/tasks.py +++ b/src/backend/apps/event/tasks.py @@ -1,6 +1,8 @@ +import datetime import logging from zoneinfo import ZoneInfo +import pytz from apps.event.enums import EVENT_DIFF_FIELDS, EVENT_STATUS, EVENT_UPDATE_FIELDS from apps.event.models import Event from apps.event.serializers import EventInternalSerializer @@ -81,6 +83,14 @@ def populate_event_from_data(new_event_data): event_serializer.save() +def cap_time_to_now(datetime_value): + # Use current time instead of future time + if datetime_value and datetime_value > datetime.datetime.now(pytz.utc): + return datetime.datetime.now(pytz.timezone('America/Vancouver')) + + return datetime_value + + def populate_all_event_data(): client = FeedClient() closures, chain_ups = client.get_dit_event_dict() @@ -112,8 +122,12 @@ def populate_all_event_data(): # DBC22-3081 replace timezone with DIT API data if cars_data['timezone']: new_tz = ZoneInfo(cars_data['timezone']) - event_data["first_created"] = event_data["first_created"].replace(tzinfo=new_tz) - event_data["last_updated"] = event_data["last_updated"].replace(tzinfo=new_tz) + + first_created_time = event_data["first_created"].replace(tzinfo=new_tz) + event_data["first_created"] = cap_time_to_now(first_created_time) + + last_updated_time = event_data["last_updated"].replace(tzinfo=new_tz) + event_data["last_updated"] = cap_time_to_now(last_updated_time) # Populate db obj populate_event_from_data(event_data) diff --git a/src/backend/apps/feed/fields.py b/src/backend/apps/feed/fields.py index aa1b88db8..c956e7a95 100644 --- a/src/backend/apps/feed/fields.py +++ b/src/backend/apps/feed/fields.py @@ -1,6 +1,3 @@ -import datetime - -import pytz from apps.shared.helpers import parse_and_localize_time_str from django.contrib.gis.geos import Point from rest_framework import serializers @@ -39,10 +36,6 @@ def __init__(self, custom_field_name, *args, **kwargs): def to_internal_value(self, value): datetime_value = super().to_internal_value(value) - # Use current time instead of future time - if datetime_value and datetime_value > datetime.datetime.now(pytz.utc): - datetime_value = datetime.datetime.now(pytz.timezone('America/Vancouver')) - res = { self.custom_field_name: datetime_value, }