Skip to content

Commit

Permalink
Fixed _format_datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
yash-metron committed Feb 27, 2025
1 parent 7663fd1 commit bc7c564
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
9 changes: 3 additions & 6 deletions Packs/Doppel/Integrations/Doppel/Doppel.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,9 @@ def format_datetime(timestamp_str):
return timestamp_str # Already in ISO format
except ValueError:
datetime_obj = arg_to_datetime(timestamp_str)
# Convert datetime object to string
date_str = datetime_to_string(datetime_obj)
# Convert to datetime object
dt_obj = datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S.%f%z")
# Convert to ISO 8601 format
iso_format_truncated = dt_obj.isoformat(timespec='seconds')

# Convert to standard ISO 8601 format without microseconds and timezone
iso_format_truncated = datetime_obj.strftime("%Y-%m-%dT%H:%M:%S")
return iso_format_truncated


Expand Down
12 changes: 3 additions & 9 deletions Packs/Doppel/Integrations/Doppel/Doppel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,15 +903,9 @@ def test_format_datetime():
# Test None input
assert format_datetime(None) is None

# Test non-ISO datetime
non_iso_input = "Feb 27, 2025 14:30"
expected_output = datetime.strptime("Feb 27, 2025 14:30", "%b %d, %Y %H:%M").isoformat()
assert format_datetime(non_iso_input) == expected_output

# Test another format
non_iso_input_2 = "27-02-2025 14:30"
expected_output_2 = datetime.strptime("27-02-2025 14:30", "%d-%m-%Y %H:%M").isoformat()
assert format_datetime(non_iso_input_2) == expected_output_2
# Test non-ISO datetime (without mocking)
assert format_datetime("Feb 27, 2025 14:30") == "2025-02-27T14:30:00"
assert format_datetime("27-02-2025 14:30") == "2025-02-27T14:30:00"

# Test invalid format
with pytest.raises(ValueError):
Expand Down

0 comments on commit bc7c564

Please sign in to comment.