deepdiff icon indicating copy to clipboard operation
deepdiff copied to clipboard

DeepDiff cannot distinguish between datetime timezones

Open iusedmyimagination opened this issue 1 year ago • 1 comments

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 avatar Jun 19 '24 19:06 iusedmyimagination

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)}}}

iusedmyimagination avatar Jun 19 '24 23:06 iusedmyimagination