TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Whenever: Typed and DST-safe datetimes for Python

286 点作者 pkkm大约 1 个月前

19 条评论

Hasnep大约 1 个月前
If you&#x27;ve not read the blog post that explains why this library exists I recommend it. It&#x27;s called &quot;Ten Python datetime pitfalls, and what libraries are (not) doing about it&quot;<p><a href="https:&#x2F;&#x2F;dev.arie.bovenberg.net&#x2F;blog&#x2F;python-datetime-pitfalls&#x2F;" rel="nofollow">https:&#x2F;&#x2F;dev.arie.bovenberg.net&#x2F;blog&#x2F;python-datetime-pitfalls...</a>
评论 #43674799 未加载
评论 #43673628 未加载
评论 #43676024 未加载
评论 #43672710 未加载
wesselbindt大约 1 个月前
Ah nice it solves the Liskov violation that the standard library has. In the standard library, dates can be compared with &lt;, and datetimes are dates. But compare a datetime with a date with &lt;, and you get an error. This drove me nuts at work recently.<p>I wonder what benefits this choice has that outweigh the risks of this behavior.
评论 #43671912 未加载
评论 #43671823 未加载
JimDabell大约 1 个月前
I’ve tried Arrow, Delorean, and Pendulum, plus the stdlib datetime of course, and settled on Whenever. It fits what I actually do with datetimes better, plus it seems more actively maintained. With the others I always seem to have a nagging feeling in the back of my mind that I am missing a whole load of edge cases. With Pendulum that seems more baked into the API.
mixmastamyk大约 1 个月前
Sounds like we need an industry&#x2F;language-wide test suite to check these many date&#x2F;time&#x2F;calendar libraries against. Like the browser acid tests, though focused to baseline functionality only.<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Acid3" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Acid3</a><p>I like this new lib (Thank You) but the name unfortunately implies the opposite of what it is. &quot;Whenever&quot; sounds like you don&#x27;t care, but you&#x27;d only be using this if you <i>did</i> care! Also Shakira, haha. Hmm, pedantic is taken. Timely, precise, punctual, meticulous, ahorita, pronto, etc. I like that temporal name.<p>Finally, none of these links mention immutability, but it should be mentioned at the top.
评论 #43675765 未加载
apeters大约 1 个月前
Am I the only one to stick with the std lib, read the docs and changelogs carefully, and implement functions I really need the way my application makes use of them?<p>I learned the hard way, that dependencies kill projects.<p>Not saying this isn&#x27;t great, thanks for creating it! It does have its use cases, of course.
评论 #43672024 未加载
评论 #43671977 未加载
评论 #43672246 未加载
评论 #43673373 未加载
评论 #43673802 未加载
评论 #43672397 未加载
评论 #43672406 未加载
评论 #43674965 未加载
评论 #43672900 未加载
评论 #43671931 未加载
评论 #43672393 未加载
Kwpolska大约 1 个月前
&gt; available in Rust or pure Python.<p>Hard pass. The complexity of having to use binary packages or build things is not worth the performance benefit. The pure-Python version requires building from source and passing special flags, so it is not possible to specify it in requirements.txt.
评论 #43671900 未加载
评论 #43674984 未加载
评论 #43671929 未加载
kelseydh大约 1 个月前
A big revelation for me in solving so much timezone insanity came from realising that timezones should be expressed as locations rather than zones.<p>Avoid general terms like &quot;Pacific Standard Time&quot; and stick to location-specific ones like: &quot;Vancouver&#x2F;Canada&quot;. The latter is how people expect their time to work, and correctly handles whatever quirky choices jurisdictions choose to do with their time.
评论 #43678085 未加载
评论 #43679005 未加载
wodenokoto大约 1 个月前
Funny it doesn’t add comparison to date times in pandas, which is probably used to handle more dates than any of the others.
评论 #43673753 未加载
qwertox大约 1 个月前
&gt; If performance isn&#x27;t your top priority, a pure Python version is available as well.<p>Then it would have been nice to see the benchmarks of the pure Python implementation as well. What if it&#x27;s worse than arrow?
评论 #43673720 未加载
vjerancrnjak大约 1 个月前
Does someone know when these performance issues matter? My understanding is that datetime is a shortlived object, you wouldn&#x27;t want thousands of datetime objects all over the codebase.<p>Almost all of the time UTC is enough, if I need to filter&#x2F;bucket&#x2F;aggregate by some range, I can reach for datetime with tz for these filter&#x2F;bucket&#x2F;aggregate criteria, convert them to UTC and on continues `int` comparison.<p>I&#x27;d imagine all of the cases handled by Whenever are mostly when datetime is a long lived object, which I don&#x27;t see a need for at all.<p>I use it purely for allowing tz input from client, convert to UTC immediately when it arrives, or, if I really need the tz, then save it separately, which is rare (one example is calendar, where tz should be stored, although probably not even next to every UTC but at the user level, another is workforce scheduling, where 8am-4pm or 8pm-4am can mean different things for different locations -- but this is no longer datetime, it&#x27;s purely time in a timezone).
评论 #43673553 未加载
snvzz大约 1 个月前
A tangent, but I hope the world gets its shit together and gets rid of DST.<p>I am currently enjoying DST-free life in Japan, and feel that people around the world deserve to get this much respect from their own official clocks.
评论 #43671936 未加载
评论 #43672862 未加载
atbpaca大约 1 个月前
I like that the type names are the same as in Java (java.time package). Great work!
skeledrew大约 1 个月前
I go for Arrow when I want anything beyond the basics. This looks pretty interesting, not really because of the greater coverage in edge cases, but because while it has a Rustified mode, a pure Python mode is also available. If I do use whenever, I don&#x27;t have to worry about having something else or falling back to datetime if I want better datetime handling in a project on my phone, or in some other environment where the Rust toolchain is non-existent or problematic. Kudos.
darthrupert大约 1 个月前
Looks amazing. I had to deal with time handling in my very first programming job 25 years ago, and lousy handling has been a pet peeve of mine ever since.
BrandoElFollito大约 1 个月前
Dates and HTTP requests are the two things I always manipulate through libraries (no matter the language, except maybe for timestamps). It is so much simpler that way.<p>I am an amateur dev, though, so maybe someone who masters the language will be better off using the raw standard libraries.
评论 #43674096 未加载
iknownothow大约 1 个月前
I&#x27;ve read the link and the GitHub readme page.<p>I&#x27;m sure I&#x27;m in the top 1% of software devs for the most number of timestamps parsed. [1]<p>DST is not a problem in Python. It&#x27;s parsing string timestamps. All libraries are bad, including this one, except Pandas. Pandas does great at DST too btw.<p>And I&#x27;m not shilling for Pandas either. I&#x27;m a Polars user who helicopters Pandas in whenever there&#x27;s a timestamp that needs to be parsed.<p>Pandas has great defaults. Here&#x27;s string timestamps I expect to be paesed by default. I&#x27;m willing to pass timezone in case of naive timestamps:<p>* All ISO 8601 formats and all its weird mutant children that differ by a tiny bit.<p>* 2025-05-01 (parsed not as date, but as timestamp)<p>* 2025-05-01 00:00:00 (or 00.0 or 00.000 or 0.000000 etc)<p>* 2025-05-01 00:00:00z (or uppercase Z or 00.0z or 00.000z or 0.000000z)<p>* 2025-05-01 00:00:00+02:00 (I don&#x27;t need this converted to some time zone. Store offset if you must or convert to UTC. It should be comparable to other non naive timestamps).<p>* 2025-03-30 02:30:00+02:00 (This is a non existent timestamp wrt European DST but a legitimate timestamp in timestamp representation, therefore it should be allowed unless I specify CET or Europe&#x2F;Berlin whatever)<p>* There&#x27;s other timestamps formats that are non standard but are obvious. Allow for a Boolean parameter called accept_sensible_string_parsing and then parse the following:<p><pre><code> \* 2025-05-01 00:00 (HH:mm format) \* 2025-05-01 00:00+01:00 (HH:mm format) </code></pre> [1] It&#x27;s not a real statistic, it&#x27;s just that I work with a lot of time series and customer data.<p>Disclaimer: I&#x27;m on the phone and on the couch so I wasn&#x27;t able to test the lib for its string parsing before posting this comment.
评论 #43674916 未加载
dwattttt大约 1 个月前
I really hoped this was about <a href="https:&#x2F;&#x2F;www.dangermouse.net&#x2F;esoteric&#x2F;whenever.html" rel="nofollow">https:&#x2F;&#x2F;www.dangermouse.net&#x2F;esoteric&#x2F;whenever.html</a>
davidkwast大约 1 个月前
I am still trying to cope with pytz and dateutils
throwaway2037大约 1 个月前
Reading this post and comment section makes me shake my head. This looks like a near clone of Java JSR-310 (new date&#x2F;time APIs), which was headed by the original author of Joda Time (Stephen Colebourne). Java 8 (and JSR-310) was released in 2014 -- 11 years ago(!). Amazingly, Python has suffered with their date&#x2F;time libs this whole time with very little concerted effort to create new date&#x2F;time APIs in the standard library. It&#x27;s pathetic. I know I will be downvoted for this post, but I don&#x27;t care. The Python standard library has so many of these awful weaknesses that other languages handle better. Except for machine learning R&amp;D, I never recommend to use Python for any enterprise project except trivial ones. You are walking into a double trap of (1) weak types and (2) weak standard library.