There’s also dateutils with commands like dateadd, dateseq, and others: https://www.fresse.org/dateutils/
Wow! This is great!
this is cool.
I recently implemented a simpler version of this solely focused on duration math which avoids ambiguities by 1) only accepting one format for durations, 2) only using units with a consistent definition (weeks, days, hours, minutes, seconds): https://github.com/alilleybrinker/dcalc
I’ve made an implementation of the duration math that also works pretty reasonably with months and years. The calculation for a difference between dates A and B is in short:
This leads to fairly intuitive differences, such as
Having longer durations be expressed as years and months instead of just weeks is really nice.
Note that this works because you have access to the original dates the duration is calculated from, and you can’t do any calculations with the resulting difference. So this is mainly just useful for presenting differences between dates
Interesting, personally I would view the second example as 1 month, 3 days (3 days until the February 1st, then one month until March 1st). To me, if you go from a date in one month to at least the same date in the following month, then one month has passed.
I love this.
I’ve struggled to word this before, but one of the things I like about shell (the payoff for suffering its sharp corners) is that every function and external program can accept its own humane word-oriented syntax–as long as the domain doesn’t need indentation or punctuation that shell doesn’t cede control of.
It often gets snowed under other layers of complexity, but quick access to idiomatic DSLs such as sql, jq, awk, sed, expect, etc. is one of those things that always strikes me as an under-appreciated superpower.
(I realize dte isn’t shell–but it’s got the kind of very-compatible grammar that I can imagine being pleasant to drop into for datetime operations.)
dte is minimalist cool text editor.