I'm fixing a whole set of bugs regarding weeks spanning year ends (the
week year, wy, didn't get propagated correctly in all cases when
converting between months, weeks, days etc).
A tricky case is this:
> Calendar.ISO.Week(2008,1)->set_size(Calendar.ISO.Day());
(1) Result: Day(Mon 31 Dec 2008)
> Calendar.ISO.Week(2008,1)->set_size(Calendar.ISO.Day())->format_ymd();
(2) Result: "2007-12-31"
> Calendar.ISO.Week(2008,1)->set_size(Calendar.ISO.Day())->year_no();
(3) Result: 2008
(2007-12-31 is the Monday of the first week of 2008.) Note the bogus
year in result (1). format_ymd however handles it correctly due to a
special check of the year day, yd:
sprintf("%04d-%02d-%02d",((yd < 1)?y-1:y),m,md)
Fixing _sprintf to do the same thing means putting the same special
check into YMD.year_name.
But what about year_no that returns 2008? Although the whole week
belongs to 2008, I expect to get 2007 for the first day of it. Looking
at it that way it seems better to ensure yd > 0 always, so that the
year is normalized. However, there is obviously an intention behind
the current behavior when yd can be <= 0, so that's why I ask.