hroptatyr / dateutils

nifty command line date and time utilities; fast date calculations and conversion in the shell
http://www.fresse.org/dateutils/
Other
617 stars 42 forks source link

Allow infinite sequences (dateseq) #165

Open Entze opened 2 weeks ago

Entze commented 2 weeks ago

Proposal: Extend dateseq to also generate a sequence of infinite dates, similar to the yes program which outputs a given string until interrupted.

For example:

dateseq --skip Saturday,Sunday 1970-01-01 1d 1970-12-31 | sed --regexp-extended '/[0-9]{4}-11-01/d'

This would output all weekdays in 1970 that are not the first of November. Which is already supported.

Additionally, the program should support more complex date filtering, where the LAST date is not known in advance. In this case, the program should continue outputting dates until a filtering condition is met, without requiring the user to know the final date in advance. For example:

dateseq --skip Saturday,Sunday 1970-01-01 1d | filter | head --lines 1

This would output the first date that passes the filter condition (or loop indefinitely), without needing to specify a LAST date.

Please let me know if you have any other questions or need further clarification.

hroptatyr commented 2 weeks ago

Hi Lukas,

thanks for the suggestion. I like your idea and I can see use cases for your suggestions. However, dateutils operates in a very limited range of dates (starting 1601-01-01 and ending 4095-12-31). If I were to implement your idea of being allowed to skip LAST, it would still cut off at the maximum date. There's only so much you can pack in a 64bit integer.

Reading beyond what you said, it appears you want some tool to do date algebra. dateseq is just a quick way of getting the set of all dates. I've been thinking about this, too. But I'm too incompetent to figure out the language design. I usually end up using Prolog to "solve" date algebra problems.