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 cannot distinguish between datetime timezones #466

Open
iusedmyimagination opened this issue Jun 19, 2024 · 1 comment
Open

DeepDiff cannot distinguish between datetime timezones #466

iusedmyimagination opened this issue Jun 19, 2024 · 1 comment

Comments

@iusedmyimagination
Copy link

DeepDiff reports all datetime timezones as equal

import datetime
import deepdiff

a = datetime.timezone.utc
b = datetime.timezone(datetime.timedelta(hours=1))
c = datetime.timezone(datetime.timedelta(hours=2))
d = datetime.timezone(datetime.timedelta(hours=1))

deepdiff.DeepDiff(a, b)
Out: {}

a == b
Out: False

deepdiff.DeepDiff(a, c)
Out: {}

a == c
Out: False

deepdiff.DeepDiff(b, c)
Out: {}

b == c
Out: False

b == d
Out: True

deepdiff.DeepDiff(b, d)
Out: {} # as expected

Expected behavior
DeepDiff of each distinct pair of a, b, c should be non-empty.

OS, DeepDiff version and Python version (please complete the following information):

  • OS: Mac OS
  • Version 14.4.1
  • Python Version 3.12.12
  • DeepDiff Version 7.0.1
@iusedmyimagination
Copy link
Author

Since datetime.timezone equality is defined as:

    def __eq__(self, other):
        if isinstance(other, timezone):
            return self._offset == other._offset
        return NotImplemented

and offset is a time delta:

    def __new__(cls, offset, name=_Omitted):
        if not isinstance(offset, timedelta):
            raise TypeError("offset must be a timedelta")

I would expect DeepDiff to return a diff of datetime.delta:

deepdiff.DeepDiff(b, c)
Out: {'values_changed': {'root': {'new_value': datetime.timedelta(seconds=7200),
   'old_value': datetime.timedelta(seconds=3600)}}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant