Range function to generate a list of dates between two dates
ghallak opened this issue · comments
Sometimes, I find myself writing a function to generate a list of dates between two given dates, like this:
dateRange : Date -> Date -> List Date
dateRange firstDate lastDate =
case Date.compare firstDate lastDate of
GT ->
[]
_ ->
firstDate :: dateRange (Date.addDays 1 firstDate) lastDate
With the available library functions addMonths
, addHours
, addMinutes
, etc.., the range
function can be generalised to create ranges for different intervals (months, hours, minutes, etc...).
Would you consider adding such a function to the elm-time
library?
I have never heard of this use case; what are you using this function for? Are you building a calendar?
The community packages are intended to be basic building blocks that:
- Are difficult or time-consuming to build on your own.
- Have general applicability without being too specific.
To me, this sounds as though you have a fine opportunity to build a "calendar" or "datebook" package application and utilize your function above there instead.
Thanks for your suggestion. I like it but think that it belongs with the package that would incorporate it.
You're right, I'm building a calendar and using this function to generate lists of dates, and it came to my mind that I should post this suggestion here to see what you think about it.
Thanks for your reply.