[Zope-dev] Zope 2 PropertyManager: editing date properties

yuppie y.2011 at wcm-solutions.de
Wed Mar 9 04:53:58 EST 2011


Hi!


AFAICS editing date properties is broken. But before I check in a fix, 
I'd like to make sure the current behavior is not a feature.

The dual nature of DateTime objects marked as timezoneNaive is hard to 
grasp: They are offset-naive *and* have a time zone. Only one of both 
aspects can be respected in a specific situation. And there might be 
different opinions which aspect is more important on the 'Properties' 
tab of PropertyManager objects.

BTW: I think it was a mistake to add a timezoneNaive flag instead of 
setting the timezone value of offset-naive DateTime objects to None.


This is the issue in the 'Properties' tab:
------------------------------------------

If you set a date property to '2011/03/09 11:00:00' and the machines 
time zone is 'GMT+1', this kind of DateTime object is created:

     >>> dt = DateTime('2011/03/09 11:00:00')
     >>> dt.timezoneNaive()
     True
     >>> dt.timezone()
     'GMT+1'
     >>> dt.asdatetime()
     datetime.datetime(2011, 3, 9, 11, 0)

After saving this DateTime object, '2011/03/09 11:00:00 GMT+1' is shown 
on the 'Properties' tab. Note that our input didn't include a time zone 
and the persistent object is marked as offset-naive. That's caused by 
the __str__ method of DateTime:

     >>> str(dt)
     '2011/03/09 11:00:00 GMT+1'

If you don't touch that setting and save the form again, this kind of 
DateTime object is created:

     >>> dt = DateTime('2011/03/09 11:00:00 GMT+1')
     >>> dt.timezoneNaive()
     False
     >>> dt.timezone()
     'GMT+1'
     >>> dt.asdatetime()
     datetime.datetime(2011, 3, 9, 11, 0, tzinfo=<StaticTzInfo 'GMT+1'>)


If I set a date property to '2011/03/09 11:00:00', I expect it stays 
marked as offset-naive if I save it twice. So I think the 'Properties' 
tab should show '2011/03/09 11:00:00' without time zone if the object is 
marked as offset-naive.


But maybe other people expect the time zone doesn't change and don't 
care about naive or not. This creates a naive DateTime object with a 
different time zone:

     >>> dt = DateTime('2011-03-09 11:00:00')
     >>> dt.timezoneNaive()
     True
     >>> dt.timezone()
     'GMT+0'

Currently the time zone is preserved, but not the naive marker:

     >>> dt = DateTime('2011/03/09 11:00:00 GMT+0')
     >>> dt.timezoneNaive()
     False
     >>> dt.timezone()
     'GMT+0'

With the fix I propose the naive marker is preserved, but not the time zone:

     >>> dt = DateTime('2011/03/09 11:00:00')
     >>> dt.timezoneNaive()
     True
     >>> dt.timezone()
     'GMT+1'

I would argue the people who don't care about naive or not should set 
the time zone explicitly. In that case the DateTime objects are always 
marked as offset-aware and the proposed fix will not affect them.

Any opinions?


Cheers,

	Yuppie


More information about the Zope-Dev mailing list