Open dtomvan opened 3 months ago
Whoops, I see the tests aren't passing. Is it because I technically did a breaking change in the datepatterns.txt? Even though I just added optional parts to existing patterns...
Sorry for the late reply. I like the idea, I want to get this merged. This changes look good, but there are a few things that need to be addressed:
now()
calls will crash in wasm builds unfortunately, so it's important to use the Context::now
field instead. That will require some plumbing to make it available here.tests/query.rs
where you can run a rink query all the way from input text to output text.I took a look at the failing datepattern tests, it seems to have been a bug in how optional patterns are matched. Not sure how to fix that, but the workaround was pretty simple. Changed:
[today[:[adddays][-subdays]]] hour12:min[:sec] meridiem[ offset]
[today[:[adddays][-subdays]]] hour24:min[:sec][ offset]
to this:
today[:[adddays][-subdays]] hour12:min[:sec] meridiem[ offset]
today[:[adddays][-subdays]] hour24:min[:sec][ offset]
hour12:min[:sec] meridiem[ offset]
hour24:min[:sec][ offset]
I can take a look into the other issues once I have more time. Thanks for working on this!
That's alright, I'm not too active on Github anyways... I don't really know your codebase well, so I hope I'm not impolite if I let you figure out how to fix those issues for now. If you do need it for some reason I'm happy to help, but I've got some other priorities right now. Nevertheless I like your program very much as it's very useful. I've got it installed as a PWA on my android phone and I use it for quick calculations on my computer as well. Thank you very much for creating this useful calculator! It seems that this is the only simple, self-contained, unit-aware one out there.
I was looking at your project and really liked it, especially for some quick date calculations, such as
#2023-05-03# - #2024-06-22# in months;weeks;days
which turned out to be so simple to do compared to spinning up either a spreadsheet, node.js, python etc. What I was missing though was, as you might've guessed, a feature to specify relative dates such astoday:-1
... This way the above calculation could've been just:#2023-05-03# - #today# in months;weeks;days
! Hence this PR.As for the code, it is a tad copy-pasty, but the MVP is there. I constrained it to "just" weeks and days, as to keep it a bit more sane. I hope you like the idea!