Merge pull request #1 from Software-Engineering-Arena/claude/fix-date-parsing-format-011CUv1KnHTFz2RZ9D2mXrDs
Browse files
app.py
CHANGED
|
@@ -80,18 +80,21 @@ def normalize_date_format(date_string):
|
|
| 80 |
"""
|
| 81 |
Convert date strings to standardized ISO 8601 format with Z suffix.
|
| 82 |
Handles both old format (2025-10-15T23:23:47.983068) and new format (2025-10-15T23:23:47Z).
|
|
|
|
| 83 |
"""
|
| 84 |
if not date_string or date_string == 'N/A':
|
| 85 |
return 'N/A'
|
| 86 |
|
| 87 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
# Parse the date string (handles both with and without microseconds)
|
| 89 |
-
|
| 90 |
-
# Old format with microseconds
|
| 91 |
-
dt = datetime.fromisoformat(date_string.replace('Z', '+00:00'))
|
| 92 |
-
else:
|
| 93 |
-
# Already in correct format or GitHub format
|
| 94 |
-
return date_string
|
| 95 |
|
| 96 |
# Convert to standardized format
|
| 97 |
return dt.strftime('%Y-%m-%dT%H:%M:%SZ')
|
|
|
|
| 80 |
"""
|
| 81 |
Convert date strings to standardized ISO 8601 format with Z suffix.
|
| 82 |
Handles both old format (2025-10-15T23:23:47.983068) and new format (2025-10-15T23:23:47Z).
|
| 83 |
+
Also handles space separator (2025-06-23 07:18:28) and incomplete timezone offsets (+00).
|
| 84 |
"""
|
| 85 |
if not date_string or date_string == 'N/A':
|
| 86 |
return 'N/A'
|
| 87 |
|
| 88 |
try:
|
| 89 |
+
# Replace space with 'T' for ISO format compatibility
|
| 90 |
+
date_string = date_string.replace(' ', 'T')
|
| 91 |
+
|
| 92 |
+
# Fix incomplete timezone offset (+00 or -00 -> +00:00 or -00:00)
|
| 93 |
+
if date_string[-3:-2] in ('+', '-') and ':' not in date_string[-3:]:
|
| 94 |
+
date_string = date_string + ':00'
|
| 95 |
+
|
| 96 |
# Parse the date string (handles both with and without microseconds)
|
| 97 |
+
dt = datetime.fromisoformat(date_string.replace('Z', '+00:00'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
# Convert to standardized format
|
| 100 |
return dt.strftime('%Y-%m-%dT%H:%M:%SZ')
|