What should the type of data be that is stored in a Datetime field in Plone 5.2?
- Zope DateTime?
- Python datetime with timezone information?
- Python datetime without timezone information?
Background: I have a site that I am migrating from Plone 4.3 Archetypes to Plone 5.2 Dexterity. In the resulting 5.2 site after migration, I am seeing all three versions of data in Datetime fields.
- The standard effective date field of both migrated and new items is Zope DateTime. This is actually what I expected everywhere.
- My custom migrated content has Python datetime with timezone information. The data of this field was migrated using
migrate_datetimefield, following the documentation from
- Newly created custom content has Python datetime without timezone information.
Naturally, this leads to various kinds of
TypeErrors when I need to compare these three kinds of dates:
TypeError: can't compare datetime.datetime to DateTime TypeError: can't compare datetime.datetime to long TypeError: can't compare offset-naive and offset-aware datetimes
My field definition is this:
start_time = schema.Datetime( title=_(u"label_start_time", default=u"Start"), required=True, )
What I now notice in
plone.app.dexterity, is that the field definition of the
effective date has this extra line:
This widget is from
I guess this is what makes it a Zope DateTime.
[Update: wrong. Adding this directive to my field and creating a new instance, I still get Python datetime without timezone info.]
So is it best to use this widget for all Datetime fields in 5.2? (Except in probably rare edge cases.)
And should I adapt my migration to keep the Zope DateTime objects?