3 ms·
Datetimes are naive in my database. The fundamental problem with the change you recommend is that I cannot then compare those two different datetimes. For examp
by aftbit 3y ago
Datetimes are naive in my database. The fundamental problem with the change you recommend is that I cannot then compare those two different datetimes. For example, today I might do:
user_over_30d_old = user.created_at < datetime.datetime.utcnow() - datetime.timedelta(30)
But in the future, I would need to do:
user_over_30d_old = user.created_at.replace(tzinfo=datetime.UTC) < datetime.datetime.now(datetime.UTC) - datetime.timedelta(30)
Which isn't any better than the solution I proposed above, of removing UTC from the now() datetime. Alternatively, I could modify my DAL code to promote datetimes from naive to timezoned in the database at the edge of the python layer, but that would have a lot of knock-on effects in things like isoformat() now appending timezone information, which has caused issues in other broken APIs that I use.