Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeepDiff Fails to Detect Timezone Changes in Arrays with ignore_order=True #517

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions deepdiff/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,10 @@ def datetime_normalize(truncate_datetime, obj):
obj = obj.replace(minute=0, second=0, microsecond=0)
elif truncate_datetime == 'day':
obj = obj.replace(hour=0, minute=0, second=0, microsecond=0)
if isinstance(obj, datetime.datetime):
obj = obj.replace(tzinfo=datetime.timezone.utc)
elif isinstance(obj, datetime.time):
obj = time_to_seconds(obj)
if isinstance(obj, datetime.datetime):
obj = obj.replace(tzinfo=datetime.timezone.utc)
elif isinstance(obj, datetime.time):
obj = time_to_seconds(obj)
return obj


Expand Down
25 changes: 24 additions & 1 deletion tests/test_diff_datetime.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
from datetime import date, datetime, time
from datetime import date, datetime, time, timezone
from deepdiff import DeepDiff


class TestDiffDatetime:
def test_datetime_within_array_with_timezone_diff(self):
"""Testing for the correct setting and usage of epsilon."""
d1 = [datetime(2020, 8, 31, 13, 14, 1)]
d2 = [datetime(2020, 8, 31, 13, 14, 1, tzinfo=timezone.utc)]

res = DeepDiff(d1, d2)
expected = {
"values_changed": {
"root[0]": {
"new_value": datetime(2020, 8, 31, 13, 14, 1, tzinfo=timezone.utc),
"old_value": datetime(2020, 8, 31, 13, 14, 1),
}
}
}
assert res == expected

res_ignore = DeepDiff(d1, d2, ignore_order=True)
assert res_ignore == expected

res_truncate = DeepDiff(d1, d2, truncate_datetime='second')
assert res_truncate == {}


def test_datetime_diff(self):
"""Testing for the correct setting and usage of epsilon."""
d1 = {"a": datetime(2023, 7, 5, 10, 11, 12)}
Expand Down