freenode/lisp - IRC Chatlog
Search
17:33:02
jasom
Just so I don't reinvent the wheel; is there a library for giving the number of weekdays between two timestamps?
18:01:08
aeth
Fortunately, it's not as bad as it sounds because there are only about a dozen or two years. I guess there would be 14: a Jan 1 with each day of the week and the presence or absence of Feb 29. Intervals that cross multiple years could complicate things, though.
18:42:15
jackdaniel
https://github.com/McCLIM/McCLIM/blob/master/Core/clim-basic/extended-streams/text-formatting.lisp#L187
19:11:44
jackdaniel
ACTION desperately tries not to make a joke about comparing whose (implementation) is longer
19:38:38
jasom
xristos: I'm already using local-time, but it only has a single difference function and that only gives you the floor of the difference in years
19:49:45
_death
jasom: your best bet is to look at emacs's calendar code.. the authors also wrote a book called Calendrical Calculations and someone ported some of the code to CL https://gist.github.com/perusio/6687883
20:08:30
Xach
it is available online used for a few dollars. i think i will get a copy sometime soon.
20:08:36
ecraven
and the code is well-written, I "ported" it to Scheme (mostly just rewrite a few macros)
20:09:44
ecraven
I contacted one of the authors years ago about the Scheme port, he was very friendly, though I don't remember what he said exactly about the license
20:10:43
ecraven
ok, found the emails, he suggested that the port would still need to adhere to the original license (free for non-commercial use, I think)
20:13:10
ecraven
well, in theory, you could read the book (but not the code) and just implement the calculations yourself (depending on what exactly you need)
20:13:26
ecraven
the actual calendrical calculations are not so complex, mostly the sun/moon stuff is hard
20:14:08
ecraven
for number of weekdays, you "just" need to convert to rata die, calculate the difference, then check the weekdays
21:59:37
jasom
which is fine for my use case of "dozens of deltas with a difference of no more than a few months"
23:16:10
jasom
most of the ranges are on the order of a few days, so I don't see how precomputing would help
23:22:20
aeth
_death: There are, afaik, only 14 years. Jan 1st on each day of the week and the presence and absence of Feb 29th. So you could just store those and have rules for ranges that span multiple years.