Story Details

  • Whenever – typed and DST-safe datetimes for Python

    Posted: 2025-04-13 09:12:19

    Whenever is a Python library providing a Whenever type for representing date and time values in a more robust and intuitive way than native Python types. It's particularly focused on handling Daylight Saving Time (DST) transitions correctly and consistently, avoiding ambiguities and errors common with other approaches. Whenever objects store datetimes as UTC timestamps internally, but allow users to interact with them in local time using a specified timezone. They offer convenient methods for performing date and time arithmetic, comparisons, and formatting, while transparently managing DST transitions behind the scenes. This simplifies working with recurring events or schedules that span DST changes, eliminating the need for complex manual adjustments. The library aims to provide a clear and dependable way to manage date and time information across different timezones and DST rules.

    Summary of Comments ( 61 )
    https://news.ycombinator.com/item?id=43671308

    Hacker News users generally praised the whenever library for its focus on type safety and handling of daylight saving time (DST), which are common pain points in Python's datetime handling. Several commenters expressed interest in its approach using tagged unions for representing different kinds of time specifications. Some raised questions about the practical implications of whenever's immutability, particularly concerning performance in tight loops and modification of existing datetime objects. The discussion also touched upon alternatives like pendulum and arrow, with some users suggesting whenever offered a fresh perspective on a persistent problem. A few commenters expressed skepticism about the library's complexity and the potential for over-engineering, preferring simpler solutions where possible.