On Sat, Mar 20, 2004 at 08:15:40AM +0900, Mark Hubbart wrote: > >The need for intersection is obvious. I don't immediately see the need > >for union, however. > > DayOfMonth(1).difference(DayOfWeek(:sunday)).union( > DayOfMonth(2).intersection(DayOfWeek(:monday)) > ) This weighs a ton (reminds me of Java), how about (DayOfMonth(1) & not(DayOfWeek(:sunday))) | # maybe .not ? (DayOfMonth(2) & DayOfWeek(:monday) ) or even (dom(1) & not(dow(:sunday))) | (dom(2) & dow(:monday)) It's pretty easy to implement with the same technique Criteria uses (building the AST using Ruby expressions). Since the temporal expression must be scoped somehow (you want that for a particular month, or a number of them), a naŭ×e implementation could even use set operations (using Array); e.g. (for month == March 2004) (note: SomeDayObject objects carry complete date info, only the dom is shown here for briefness) DayOfMonth(1) => [SomeDayObject(1)] DayOfWeek(:sunday) => [SomeDayObject(7), SomeDayObject(14), SomeDayObject(21),SomeDayObject(28)] DayOfMonth(1) - DayOfWeek(:sunday) => [SomeDayObject(1)] Intersection is Array#&, union would be Array#+. You'd then just have to take the first element if you only want one day, or the whole array if you want a set. > > For example, you can create simple expressions ... > Hmm, should we overload && and || for these? Maybe someone already has. && or || can't be overloaded; & and | work nicely though. > I believe that this imaginary code would give you every first of the > month, unless it falls on a sunday, then it gives the second of the > month. Trchic! (yeah, I probly misspelled that.) I'd expect it to give out the first of the month unless it falls on a sunday, or the 2nd of the month if it is a monday (else nothing), but maybe I just have different semantics in mind. -- Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com People disagree with me. I just ignore them. -- Linus Torvalds, regarding the use of C++ for the Linux kernel