Skip to content

Commit

Permalink
[frontend/accessible_time] Applying utc timezone directly in parse_da…
Browse files Browse the repository at this point in the history
…te() and adapt_database_date()

to fix test_parsable_text tests + fixes (not applying timezone to min and max dates)
  • Loading branch information
AlexandreDoneux committed May 16, 2024
1 parent 488953d commit e13856d
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions inginious/frontend/accessible_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def parse_date(date, default=None):
for format_type in ["%Y-%m-%d %H:%M:%S", "%Y-%m-%d %H:%M", "%Y-%m-%d %H", "%Y-%m-%d", "%d/%m/%Y %H:%M:%S",
"%d/%m/%Y %H:%M", "%d/%m/%Y %H", "%d/%m/%Y"]:
try:
return datetime.strptime(date, format_type)
return datetime.strptime(date, format_type).replace(tzinfo=timezone.utc)
except ValueError:
pass
raise Exception("Unknown format for " + date)
Expand All @@ -46,8 +46,8 @@ def __init__(self, period):
Can be a boolean, None or string if using the legacy format "start/soft_end/end"
"""

self.max = datetime.max.replace(microsecond=0, tzinfo=timezone.utc)
self.min = datetime.min.replace(tzinfo=timezone.utc)
self.max = datetime.max.replace(microsecond=0)
self.min = datetime.min.replace()

if not isinstance(period, (dict, str, bool, type(None))): # add None check
raise Exception("Wrong period given to AccessibleTime")
Expand All @@ -68,10 +68,11 @@ def __init__(self, period):
if isinstance(date, str):
period[key] = parse_date(date)

self._start = period["start"].replace(tzinfo=timezone.utc)
self._end = period["end"].replace(tzinfo=timezone.utc)
self._start = period["start"].replace(tzinfo=timezone.utc) if period["start"] not in [self.min, self.max] else period["start"]
self._end = period["end"].replace(tzinfo=timezone.utc) if period["end"] != self.max else period["end"]
if "soft_end" in period:
self._soft_end = min(period["soft_end"], period["end"]).replace(tzinfo=timezone.utc)
soft_end = min(period["soft_end"], period["end"])
self._soft_end = soft_end.replace(tzinfo=timezone.utc) if soft_end != self.max else soft_end

def legacy_string_structure_to_dict(self, legacy_date):
"""
Expand Down

0 comments on commit e13856d

Please sign in to comment.