in src/validators/swagger_request_models.py [0:0]
def validate_dates(self) -> Self:
"""
What it does:
- converts start_iso and end_iso to utc tz-aware datetime object
- validates that start_iso < end_iso, end_iso <= now
- sets default values in case they are not provided
:param values:
:return:
"""
now = utc_datetime()
max_range = self.max_range()
start = self.to_datetime(self.start_iso)
end = self.to_datetime(self.end_iso)
if start:
start = start.astimezone(timezone.utc)
if start > now:
raise ValueError('value of \'from\' must be less '
'than current date')
if end:
end = end.astimezone(timezone.utc)
if end > now:
raise ValueError('value of \'to\' must be less '
'than current date')
if start and end:
pass
elif start:
end = min(start + max_range, now)
elif end:
start = end - max_range
else: # both not provided
if self.skip_validation_if_no_input:
self.start_iso = None
self.end_iso = None
return self
end = now
start = end - max_range
if start >= end:
raise ValueError('value of \'to\' must '
'be bigger than \'from\' date')
if (end - start) > max_range:
raise ValueError(
f'Time range between \'from\' and \'to\' must '
f'not overflow {max_range}')
self.start_iso = start
self.end_iso = end
return self