|
Boost : |
From: Friedrich Wilckens (fw_at_[hidden])
Date: 2005-07-17 08:57:21
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.
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.
This approach would also not limit flexibility of the date template. If
for another calendar there is some irregularity, we could for 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?
Sincerely,
Friedrich
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk