Commit 7ac33e16 authored by Jérome Perrin's avatar Jérome Perrin

DateTimePatch: keep DateTime.__eq__ behavior from DateTime 2

We have too much code depending on this behavior, so we keep this patch
for now.
parent 70345deb
...@@ -35,6 +35,15 @@ SyntaxError, DateError, TimeError, localtime, time ...@@ -35,6 +35,15 @@ SyntaxError, DateError, TimeError, localtime, time
STATE_KEY = 'str' STATE_KEY = 'str'
# DateTime 3 changed the __eq__ behavior and d1 == d2 only if they have the same same
# timezone. With DateTime 2 two dates from different timezones representing the same
# time were equal. This patch keeps the behavior from DateTime 2.
# See zopefoundation/DateTime commit fff6d04 (Various cleanups, improve unpickling
# speed and distinguish between equal representations and references to equal points
# in time., 2011-05-06)
DateTimeKlass.__eq__ = DateTimeKlass.equalTo
# ERP5 Patch for different pickle implementation, to optimize for disk usage. # ERP5 Patch for different pickle implementation, to optimize for disk usage.
# We had different __getstate__ implementations, so we need __setstate__ to support # We had different __getstate__ implementations, so we need __setstate__ to support
# loading these formats that might be present in ZODBs. # loading these formats that might be present in ZODBs.
......
  • @jerome This change introduces the following behaviour on Zope4.

    • code
    portal = context.getPortalObject()
    web_page = portal.web_page_module.newContent(
      portal_type='Web Page',
      temp_object=True,
    )
    web_page.setEffectiveDate(DateTime(0))
    print web_page.getEffectiveDate()
    print web_page.hasEffectiveDate()
    return printed
    • Zope2 result
    1970/01/01 01:00:00 GMT+1
    True
    • Zope4 result
    None
    False

    It is caused by DateTime.equalTo at https://github.com/zopefoundation/DateTime/commit/b9ddd8b9f9c8ba89fcab749a1871871706e7c2c0#diff-778daecbfbef655fab523b4aaa62847e40260011204ee3202a063367e3f35f91R1247 and Setter.__call__ at https://lab.nexedi.com/nexedi/erp5/blob/7ac33e16956cbd4684fdefbf35d25fcfff39350f/product/ERP5Type/Accessor/Base.py#L74-75 (and similar code in Tester.__call__).

    I can understand that the change in DateTime is introduced for Python3 sorting, but I think the code should be rather the following to keep Python2's sort behaviour, i.e. None is always first.

    def equalTo(self, t):
      if t is None:
        return False # instead of 't = 0'
      ...
    def greaterThanEqualTo(self, t):
      if t is None:
        return True # instead of 't = 0'
      ...
    def lessThanEqualTo(self, t):
      if t is None:
        return False # instead of 't = 0'
      ...

    Or we should 'fix' in our Accessor code ?

  • mentioned in merge request !1800 (closed)

    Toggle commit list
  • Let's continue on !1800 (closed)

Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment