I'm trying to use the Calendar module in 7.4 for some basic stuff:
Calendar.ISO.Day(2005, 03, 30);
(36) Result: Day(Wed 30 Mar 2005)
Calendar.ISO.Day(2005, 03, 30) - Calendar.ISO.Month();
(37) Result: Day(Wed 2 Mar 2005)
Is that the expected output? I'd love to hear the rationale for that. :-) (BTW, 7.7 returns the same so it's not a 7.4 issue.)
More importantly, how can I accomplish month-by-month stepping that pins the day number within the prev/next month? Of course one method would be to create Month objects manually and compare days etc but I figure it's probably already solved.
I'd say that's not the expected output, no... but what would the expected output be?
The result of lest surprice, even if it's not trivial true since the Month object is instanciated would probably be: (37) Result: Day(Wed 30 Feb 2005)
Non-existing dates wouldn't be much help, I'm afraid. I expect the output to be similar to flipping pages in a wall calendar, i.e. I should end up on the correct month no matter what. Next, the day is adjusted to fit the available range.
Mirar's workaround unfortunately doesn't help:
Calendar.ISO.Day(2005, 03, 30) - Calendar.Month() * 1;
(4) Result: Day(Wed 2 Mar 2005)
Isn't the * 1 a no-op (or optimized away)? It doesn't become a range from what I can see:
Calendar.Month() * 1;
(7) Result: Month(June 2005)
Calendar.Month() * 2;
(8) Result: Month(Jun..Jul 2005)
Everything is a range. No, it doesn't help, but when you flip to January you get the correct day again.
If you look at the example from the documentation, which is somewhat spread out and therefore a bit difficult to locate:
http://pike.ida.liu.se/generated/manual/modref/ex/predef_3A_3A/Calendar/Time...
there you see an example that sort of gives you an idea of how you step through the months.
I think I suggested a method before once, that you don't step but use *n instead from the original day,
dminus1=day-Calendar.Month()*1; dminus2=day-Calendar.Month()*2; dminus3=day-Calendar.Month()*3;
and not
dminus1=day-Calendar.Month(); dminus2=dminus1-Calendar.Month(); dminus3=dminus2-Calendar.Month();
I'd prefer day-Calendar.Month*3, I think, but that might be mostly for being tainted by the conception that Calendar.Month() is a timerange starting 00:00:00 on the first of the present month, and ending just before that time the next month. In other words, a timerange object like any other that just happens to coincide with present month, whose length depends on when you instantiate it.
Maybe it is in poor taste to consider the type Calendar.Month a good candidate for doing integer multiplication on, though.
Not meaning to stem good efforts at improving towards the result of least surprise, but I think the original design wants you to use (wanted month)->place(wanted day) for solving problems like these.
pike-devel@lists.lysator.liu.se