|
Boost : |
From: Jeff Garland (jeff_at_[hidden])
Date: 2005-07-17 10:13:45
On Sun, 17 Jul 2005 15:57:21 +0200, Friedrich Wilckens wrote
> date_time::date::day_of_week() calls two functions from the calendar
> template parameter: the first to convert the internal integer
> representation into a ymd_type, and the second to calculate the
> day_of_week for this ymd_type. Both do some non-trivial arithmetic.
True.
> I wonder why the following simpler and more efficient approach is not
> used.
>
> In date_time::date:
>
> day_of_week_type day_of_week() const
> {
> return calendar::day_of_week(days_);
> }
>
> In date_time::gregorian_calendar_base add a method:
>
> static unsigned short day_of_week(const date_int_type& d)
> {
> return (d + 1) % 7;
> }
>
> As far as I know, the sequence of weeks in the gregorian calendar is
> completely regular and this simple calculation is correct.
Yes that's true -- of course the above would have to be some adjustment for
the possibility that day 0 != Sunday...
> This approach would also not limit flexibility of the date template.
> If for another calendar there is some irregularity, we could for
And there is if you wanted to implement an 'accurate' gregorian calendar
instead of a propletic one. You'd have to adjust for all sorts of interesting
adjustments in the 1580's.
> this calendar implement
>
> static unsigned short day_of_week(const date_int_type& d)
> {
> return day_of_week(from_day_number(d));
> }
>
> Is there any problem in this reasoning?
Probably not. I'll put it on the todo list for 1.34.
Thx,
Jeff
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk