Skip to content

Commit

Permalink
Change output to use original value in error messages (needed for pyt…
Browse files Browse the repository at this point in the history
…hon 3.10 and earlier)
  • Loading branch information
joshua-hampton committed Oct 1, 2024
1 parent 7ee7741 commit 9621b92
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions checksit/rules/rule_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ def check_utc_date_iso_format(value, context, extras=None, label=""):
"""
errors = []

original_value = value
if sys.version_info < (3,11): # python datetime changed its recognition of ISO format from 3.11 onward
if value.endswith("Z"):
value = value.replace("Z", "+00:00")
Expand All @@ -402,9 +403,9 @@ def check_utc_date_iso_format(value, context, extras=None, label=""):
try:
dt = datetime.fromisoformat(value)
if (dt.utcoffset() != None) and (dt.utcoffset().total_seconds() != 0):
errors.append(f"{label} Date string '{value}' not in UTC.")
errors.append(f"{label} Date string '{original_value}' not in UTC.")
except ValueError:
errors.append(f"{label} Date string '{value}' not in ISO 8601 format.")
errors.append(f"{label} Date string '{original_value}' not in ISO 8601 format.")
except:
raise

Expand Down

0 comments on commit 9621b92

Please sign in to comment.