Shall I store `datetime` or `DateTime` objects for Dexterity Date Fields?

Hi everyone,

I just had a look into plone.dexterity.content.DexterityContent to see how the creation_date et al. are set and was wondering why it uses DateTime instead of datetime objects:

class DexterityContent(DAVResourceMixin, PortalContent, PropertyManager, Contained):
    """Base class for Dexterity content"""
    ...
    def __init__(...):
        ...
        now = DateTime()
        self.creation_date = now

Now I am wondering if it makes sense at all to store datetime objects for our custom Dexterity contents or if we should just store DateTime objects there as well.

The reason why I ask is because I just get nuts with the timezones ...

Thanks for any insights.

Ramon

Following links might help:

https://5.docs.plone.org/develop/plone/misc/datetime.html

Default plone.app.z3cform.converter returns datetime object and respects a default_timezone attribute if it exists:

Thanks @petschki, I was aware of this code.

The headaches come more when handling both DateTime to datetime and comparing timezone naive with timezone aware objects.

We wrote an whole API to wrap things up and make it a bit easier to handle:

Anyhow, we will just continue to use datetime objects in our Dexterity types and try to live with the other existing DateTime objects.

I'd also just use datetime. The older DateTime should once be replaced with Python's own datetime.

These APIs/utilities might also help:

1 Like