unsigned int GameTime::getWeek() const { date firstMonday = previous_weekday(GAME_START.date(), greg_weekday(Monday)); date lastMonday = previous_weekday(getPtime(this->ticks).date(), greg_weekday(Monday)); date_duration duration = lastMonday - firstMonday; return duration.days() / 7 + 1; }
inline std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is,greg_weekday& wd) { typedef boost::date_time::all_date_names_put<greg_facet_config, charT> facet_def; std::basic_string<charT> s; is >> s; if(!std::has_facet<facet_def>(is.getloc())) { std::locale loc = is.getloc(); charT a = '\0'; is.imbue(generate_locale(loc, a)); } short num = 0; try{ const facet_def& f = std::use_facet<facet_def>(is.getloc()); num = date_time::find_match(f.get_short_weekday_names(), f.get_long_weekday_names(), (greg_weekday::max)(), s); } /* bad_cast will be thrown if the desired facet is not accessible * so we can generate the facet. This has the drawback of using english * names as a default. */ catch(std::bad_cast bc){ //std::cout << "Weekday exception caught" << std::endl; charT a = '\0'; const facet_def* f = create_facet_def(a); num = date_time::find_match(f->get_short_weekday_names(), f->get_long_weekday_names(), (greg_weekday::max)(), s); delete(f); } wd = greg_weekday(num); // weekdays numbered 0-6 return is; }
inline std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is,greg_weekday& wd) { typedef boost::date_time::all_date_names_put<greg_facet_config, charT> facet_def; std::basic_string<charT> s; is >> s; if(!std::has_facet<facet_def>(is.getloc())) { std::locale loc = is.getloc(); charT a = '\0'; is.imbue(generate_locale(loc, a)); } short num = 0; try{ const facet_def& f = std::use_facet<facet_def>(is.getloc()); num = date_time::find_match(f.get_short_weekday_names(), f.get_long_weekday_names(), (greg_weekday::max)() + 1, s); // greg_weekday spans 0..6, so increment is needed // to form the array size which is needed by find_match } /* bad_cast will be thrown if the desired facet is not accessible * so we can generate the facet. This has the drawback of using english * names as a default. */ catch(std::bad_cast&){ charT a = '\0'; std::auto_ptr< const facet_def > f(create_facet_def(a)); num = date_time::find_match(f->get_short_weekday_names(), f->get_long_weekday_names(), (greg_weekday::max)() + 1, s); // greg_weekday spans 0..6, so increment is needed // to form the array size which is needed by find_match } wd = greg_weekday(num); // weekdays numbered 0-6 return is; }