A question regarding gregorian week_iterator

I can’t understand what, if indeed anything, I am doing wrong here. Using boost 1.69 on Arch Linux I am trying to use a gregorian::week_iterator to iterate a gregorian date_period that has a length of 365 which produces this output: Starts 2018-07-10 Ends 2019-07-10 true false true 365
From this code:
boost::gregorian::date_period dp{ m_Start, m_Ends } ; BOOST_LOG(lg) << "Starts " << boost::gregorian::to_iso_extended_string(dp.begin()) << " Ends " << boost::gregorian::to_iso_extended_string(dp.end()) << " " << isYear << " " << isMonth << " " << isWeek << " " << dp.length() ; The following is the code I am using to iterate the date_period: for(boost::gregorian::week_iterator wi = dp.begin(); wi != dp.end(); ++wi) { items.push_back(formatParams(pi, (*wi))) ; } However, when this code executes it eventually fails with the following error: Year is out of valid range: 1400..9999 In my formatParams method the code generates the correct strings, but it doesn’t stop at Jun 2019 as I’d expect but continues to run out to 2375! I would appreciate some feedback on this as I have identical code that uses a gregorian::month_iterator and this generates the 12 items from the same date_period range as I’d expect. -- Bill

Thank you for the reply Dan. Changing the iteration logic does indeed stop when expected, but for me it raises a couple of question. When using the month_iterator the != approach works so why not for the week_iterator? As the month_iterator option I have uses the same date_period approach. The second question is since the iteration is over a predefined date range whose start and ends are set why didn’t the iterations exhaust on say Aug 2019? What allowed it to continue way outside of the constrained range implying that the range is in fact much larger. -- Bill On Wed, 10 Jul 2019 at 17:48, Dan Bloomquist via Boost-users <boost-users@lists.boost.org> wrote:

Bill Moo wrote:
The functor for incriminating by week simply adds 7 to the day count and 365 % 7 != 0. For the month iterator it digs down to find the actual calendar spans for the year and month given. The 'day' of each iteration by month lands on the same day of the month. It will work for leap years. for (boost::gregorian::month_iterator mi = dp.begin(); mi < dp.end(); ++mi) { std::cout << mi->month() << " " << mi->day() << std::endl; } For boost::gregorian iterators, I would only use the '<' rather than '!=' to insure you don't miss a hit.
These are not container iterators. The iterator is valid throughout the calendar range, they are only a day position in the calendar. Much like a char* can point anywhere in memory yet char* can be treated like an iterator. There is no specialization to 'contain' the iterator. Best, Dan.
participants (3)
-
Bill Moo
-
Dan Bloomquist
-
pbristow@hetp.u-net.com