Never write your own Date Parsing Library (I wrote my own Date Parsing Library)
Zach Leatherman 6767 replies 138138 likes3737 reposts44 quotes Original on MastodonOriginal on BlueskyAlso posted to Mastodon.
67 replies
@zachleat when I first met Bitwalker who wrote the first datetime package in Elixir, my first words were “you sick bastard!”
@pete seems about right 😅
This one never got much attention but maybe useful reference. I think it's ok to write code if you're a programmer but I'm a weirdo that way.
nice! I hadn’t seen this one before either!
I too think it’s okay to write code (and by hand even)
@zachleat > As an aside, this search has made me tempted to ask: do we need to keep Dual publishing packages? I prefer ESM over CJS but maybe just pick one?
Some in the ecosystem think that we don't need to anymore, and should just ship ESM modules (see for instance https://e18e.dev/blog/migrating-the-ecosystem-to-esm.html), but it depends on what older Node.js versions you want to support.
- Supported and updated versions of Node 20 and 22? You can ship ESM only.
- Node 18 or earlier? Early (and at this point not secure) versions of Node 20 and 22? Then you need a dual package.@fvsch for the record I have never dual published a package. When 11ty swapped to ESM we went all-in on ESM with Node 18+ and it has worked fine.
Intl gets me most of the way there these days
well wait — I don’t see any date parsing things in those APIs — only formatting/display
No sorry I didn't mean to suggest I was using it for parsing. I meant for formatting. For parsing I try to avoid needing anything other than Date's quirky implementation (not always an option, I know). Kinda hoping Temporal will solve this (do you know if it will?)
I do know the answer to this and wrote a blog post about it linked above 😅
🤦♂️ I only skimmed
we’ve all been there 😅
@zachleat i'm pretty sure this is how it works, so good on you
@jimniels Geordi is one of my favorite fictional engineers so I take this as very high praise thank you
-
@scrwd JON this definitely feels more 😈 than 👼
😅
"As an aside, this search has made me tempted to ask: do we need to keep Dual publishing packages? I prefer ESM over CJS but maybe just pick one?"
Could this mean you'll drop support for CJS config in Eleventy v4? Would mean we wouldn't have to Dual publish plugins.
naw, there’s no reason to drop CJS config/data/template file support in Eleventy. It’s written in ESM but works with CJS (in Node 18 too)
None of the official Eleventy plugins are dual published either, fwiw — if they need to support core < 3, they’ll stay as CJS. If core >=3, they can be ESM-only
to be clear, CJS configs can import ESM plugins with `await import`
Nice! Seeing as smol size is a prime feature of this lib, are you open to contributions that reduce the number of minified bytes at the expense of some readability?
And how important is it that errors are specific, for example regarding fractional hours & minutes? I can see the test don’t currently capture that distinction.
I would say not very open to readability tradeoffs but also you’re right — the error messaging here is not specific: just invalid or valid
Ok, I’ll raise a PR or two, but feel free to reject ‘em!
I’ve got github.com/11ty/parse-d... and github.com/11ty/parse-d... – curious to see if you find them helpful :)
Of course all the tests still pass!
Thanks! They look good on first glance!
eww, no thank you
@zachleat plus what tho
@michael depends if you like C, C#,or C++
-
@khalidabuhakmeh I am under vicious attack by you
@zachleat @khalidabuhakmeh comes with an honorary turtleneck does this help
@slab_bulkhead @khalidabuhakmeh turtleneck versus the hareneck aka neckbeard
@zachleat @slab_bulkhead I'm not sure how to think. Could you please tell me?
@khalidabuhakmeh @slab_bulkhead when in doubt just do what Meta does
@zachleat @slab_bulkhead Cool. I've joined a Brazilian JuJitsu club, grown a fro, and having a midlife crisis as we speak. Next stop, The Joe Rogan Experience!
@khalidabuhakmeh @slab_bulkhead see you in the metaverse
@zachleat @slab_bulkhead at least the top half of me. 😅
@zachleat oh no
@zachleat You’re already writing a date parser and now it’s on HN, talk about kicking someone when they’re down
@tylersticka woke up this morning with a patagonia fleece vest on, somehow
-
only general zod can judge me
@zachleat a few years ago I had to spend 3 months of development because #safari’s date parsing had changed between versions of #ios making our server emitted dates break…
This was the perfect illustration why flawed standards such as iso8601 are a problem. And this the reason why date parsing is a nightmare…
Just be strict. Period.
And accept that this is politically incorrect.ok yeah, but what is your quiz score:
jsdate.wtfI don’t know her!!
@zachleat You’ll be taking VC investments and revolutionizing date parsing, calendars and string display in no time.
@cory hear me out what if we used AI to parse dates so that it was wrong at an even higher percentage BUT at the cost of a lot more electricity
@zachleat @cory Welcome to hell. https://www.timeanddate.com/time/time-zones-interesting.html
@khalidabuhakmeh @cory bless those folks in :45 time zones 😅
@khalidabuhakmeh @cory just gotta make sure it’s on the 45 minutes late side and not 45 minutes early 😅
- @khalidabuhakmeh @zachleat @cory Obilgatory Gaffigan https://youtu.be/ehZePNP_w4I?si=RYYv5TGaOuXRD5Z2&t=326
@daniel @cory @khalidabuhakmeh WE’LL DO HALF HOUR
- 🤖 Tracking strings detected and removed!
🔗 Clean URL(s):
https://youtu.be/ehZePNP_w4I?t=326
❌ Removed parts:
si=RYYv5TGaOuXRD5Z2&
@zachleat I mean yes, but then think of the opportunities when we install our date parser on the infrastructure underpinning the AI.
Can we get a prequel? Might i suggest "Several reasons why I think it would be a good idea to write a Date Parsing Library"
@zachleat thoughts and prayers
@mikehoss it isn’t often you get to subscribe to a future car crash, mike
-
with Eleventy v4, yeah
we’ll make it part of the upgrade plugin and provide guidance about how to keep using luxon, for the record!
@zachleat cool article! I wonder if you have also looked at how much a Temporal API polyfill might weigh in. I wonder if it is a solid option to use that and just remove it when the promised day finally comes 😄
-
@claasdev yeah, I am starting to think it might be worth a follow-up article focused on answering that question specifically!
-
I totally agree that ambiguity and too many formats are some of the hardest problems with date parsing solutions.
Thanks for trying to solve the (impossible?) task to create a Date Parsing Library.