Whenever – typed and DST-safe datetimes for Python

https://news.ycombinator.com/rss Hits: 18
Summary

⏰ Whenever Typed and DST-safe datetimes for Python, available in Rust or pure Python. Do you cross your fingers every time you work with Python's datetime—hoping that you didn't mix naive and aware? or that you avoided its other pitfalls? There’s no way to be sure... ✨ Until now! ✨ Whenever helps you write correct and type checked datetime code, using well-established concepts from modern libraries in other languages. It's also way faster than other third-party libraries—and usually the standard library as well. If performance isn't your top priority, a pure Python version is available as well. RFC3339-parse, normalize, compare to now, shift, and change timezone (1M times) ⚠️ Note: A 1.0 release is coming soon. Until then, the API may change as we gather feedback and improve the library. Leave a ⭐️ on GitHub if you'd like to see how this project develops! Why not the standard library? Over 20+ years, Python's datetime has grown out of step with what you'd expect from a modern datetime library. Two points stand out: It doesn't always account for Daylight Saving Time (DST). Here is a simple example: bedtime = datetime ( 2023 , 3 , 25 , 22 , tzinfo = ZoneInfo ( "Europe/Paris" )) full_rest = bedtime + timedelta ( hours = 8 ) # It returns 6am, but should be 7am—because we skipped an hour due to DST! Note this isn't a bug, but a design decision that DST is only considered when calculations involve two timezones. If you think this is surprising, you are not alone. Typing can't distinguish between naive and aware datetimes. Your code probably only works with one or the other, but there's no way to enforce this in the type system! # Does this expect naive or aware? Can't tell! def schedule_meeting ( at : datetime ) -> None : ... Why not other libraries? There are two other popular third-party libraries, but they don't (fully) address these issues. Here's how they compare to whenever and the standard library: Whenever datetime Arrow Pendulum DST-safe ✅ ❌ ❌ ⚠️ Typed aware/naiv...

First seen: 2025-04-13 10:00

Last seen: 2025-04-14 03:02