Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <boost/date_time/gregorian/gregorian.hpp>
- #include <boost/format.hpp>
- using namespace boost::gregorian;
- int getMonthWeek(const date& d) //here sunday is first week day
- {
- auto getYearWeek = [](const date& d){return d.week_number()+(d.day_of_week()==Sunday?1:0);};
- return getYearWeek(d) - getYearWeek(date{d.year(), d.month(), 1});
- }
- int main() {
- const int days_per_week = 7;
- const int months_per_year = 12;
- const int weeks_per_block = 6;
- const int months_per_block = 3;
- const int blocks_per_year = ceil( double( months_per_year ) / months_per_block );
- const greg_year year = 2015;
- for(auto yearblock = 0; yearblock != blocks_per_year; yearblock++) {
- int monthweek2blockmonth2weekday2monthday [weeks_per_block] [months_per_block] [days_per_week] = {};
- for(auto blockmonth = 0; blockmonth != months_per_block; blockmonth++) {
- const int yearmonth = yearblock * months_per_block + blockmonth;
- if(yearmonth < months_per_year) {
- const greg_month gregmonth = yearmonth + 1;
- std::cout << boost::str(boost::format("%|=22|") % gregmonth.as_long_string());
- for(date d{ year, gregmonth, 1 }, d_last = d.end_of_month(); d <= d_last; d += date_duration(1))
- monthweek2blockmonth2weekday2monthday [getMonthWeek(d)] [blockmonth] [d.day_of_week()] = d.day();
- }
- }
- std::cout << std::endl;
- for(const auto& blockmonth2weekday2monthday: monthweek2blockmonth2weekday2monthday) {
- for(const auto& weekday2monthday: blockmonth2weekday2monthday) {
- for(const auto& monthday: weekday2monthday)
- std::cout << ( monthday ? boost::str(boost::format("%|3|") % monthday) : " " );
- std::cout << " ";
- }
- std::cout << std::endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement