🎙️
30

Found out Python's 'datetime' module handles time zones way differently than I thought

I was working on a little project to log when I water my plants, just a simple script to track timestamps. I figured I'd just use datetime.now() and call it a day. But then I read this article on Real Python about time zone awareness, and turns out datetime objects without time zones are 'naive' and can mess up comparisons across daylight savings. I had no idea the module treats UTC times differently than local times unless you manually set pytz or zoneinfo. It blew my mind because I've been coding for maybe 6 months and thought I had the basics down. Has anyone else hit a wall with datetime quirks when starting out?
2 comments

Log in to join the discussion

Log In
2 Comments
bennett.nora
Yeah I only figured that out after five years of coding...
7
terryk10
terryk101d ago
Started out thinking it was all about clean code and frameworks. Seeing how small changes in one spot can mess up completely unrelated parts changed my mind real fast.
1