zopefoundation / DateTime

This package provides a DateTime data type, as known from Zope. Unless you need to communicate with Zope APIs, you're probably better off using Python's built-in datetime module.
Other
19 stars 25 forks source link

date only #38

Closed georgpfolz closed 2 years ago

georgpfolz commented 2 years ago

Something I often need is to convert a DateTime object to a date. This is pretty easy with the lowercase datetime class (just convert to datetime.date). With DateTime, I set the time to 00:00:00, but that's it's a bit complicated if it's meant to be timezone-safe (without changing the timezone).

Here's what I've been coming up with:

dt = DateTime()
date = dt - (dt + dt.tzoffset() / 24 / 3600)

What do you think about adding a new method date or toDate to the class? (and maybe also a method today)

I would be willing to provide a PR :)

georgpfolz commented 2 years ago

I think this is a dumb idea (apart from the code not working). As it's a time, the date can still vary from timezone to timezone, especially if its 0:00.