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.
Janet's PEG module uses a packrat parsing approach, combining memoization and backtracking to efficiently parse grammars defined in Parsing Expression Grammar (PEG) format. The module translates PEG rules into Janet functions that recursively call each other based on the grammar's structure. Memoization, storing the results of these function calls for specific input positions, prevents redundant computations and significantly speeds up parsing, especially for recursive grammars. When a rule fails to match, backtracking occurs, reverting the input position and trying alternative rules. This process continues until a complete parse is achieved or all possibilities are exhausted. The result is a parse tree representing the matched input according to the provided grammar.
Hacker News users discuss the elegance and efficiency of Janet's PEG implementation, particularly praising its use of packrat parsing for memoization to avoid exponential time complexity. Some compare it favorably to other parsing techniques and libraries like recursive descent parsers and the popular Python library parsimonious
, noting Janet's approach offers a good balance of performance and understandability. Several commenters express interest in exploring Janet further, intrigued by its features and the clear explanation provided in the linked article. A brief discussion also touches on error reporting in PEG parsers and the potential for improvements in Janet's implementation.
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 ofwhenever
's immutability, particularly concerning performance in tight loops and modification of existing datetime objects. The discussion also touched upon alternatives likependulum
andarrow
, with some users suggestingwhenever
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.The Hacker News post about Whenever, a library for typed and DST-safe datetimes in Python, has generated a moderate amount of discussion, with a focus on existing solutions and the specific problems Whenever aims to address.
Several commenters point towards existing libraries and built-in functionalities in Python that already address some of the issues Whenever tackles. One commenter highlights the
zoneinfo
module introduced in Python 3.9, suggesting it provides similar timezone handling capabilities. Another mentions thePendulum
library as a potential alternative that offers user-friendly datetime manipulation. A third points out that thedatetime
objects in Python already store timezone information, questioning the necessity of a new library.There's a discussion about the complexities of timezone handling in general. One commenter emphasizes the inherent difficulty of working with timezones and DST, suggesting that a comprehensive solution is challenging to achieve. Another adds to this by mentioning the "local time" ambiguity during DST transitions, where a specific time can exist twice or not at all, highlighting a common pain point.
The core value proposition of Whenever, namely its type safety, is also discussed. One user expresses appreciation for the static typing aspect, which can help prevent errors related to timezone handling at compile time. This resonates with another commenter who also sees value in the type hints provided by the library.
Finally, some commenters express skepticism about the library's usefulness. One suggests that using UTC consistently and only converting to local time for display purposes is a simpler approach. This sentiment is echoed by another who advocates for sticking with UTC and formatting time zones on output as a more straightforward solution.