//! Returns a negative duration_type duration_type get_neg_offset(const date_type& d) const { ymd_type ymd(d.year_month_day()); if (origDayOfMonth_ == 0) { origDayOfMonth_ = ymd.day; day_type endOfMonthDay(cal_type::end_of_month_day(ymd.year,ymd.month)); if (endOfMonthDay == ymd.day) { origDayOfMonth_ = -1; //force the value to the end of month } } typedef date_time::wrapping_int2<short,1,12> wrap_int2; typedef typename wrap_int2::int_type int_type; wrap_int2 wi(ymd.month); //calc the year wrap around, add() returns 0 or 1 if wrapped int_type year = wi.subtract(static_cast<int_type>(f_)); year = static_cast<int_type>(year + ymd.year); //calculate resulting year //find the last day for the new month day_type resultingEndOfMonthDay(cal_type::end_of_month_day(year, wi.as_int())); //original was the end of month -- force to last day of month if (origDayOfMonth_ == -1) { return date_type(year, wi.as_int(), resultingEndOfMonthDay) - d; } day_type dayOfMonth = origDayOfMonth_; if (dayOfMonth > resultingEndOfMonthDay) { dayOfMonth = resultingEndOfMonthDay; } return date_type(year, wi.as_int(), dayOfMonth) - d; }
//! Put date into an ostream static void date_put(const date_type& d, ostream_type& os, const facet_type& f) { special_values sv = d.as_special(); if (sv == not_special) { ymd_type ymd = d.year_month_day(); ostream_ymd_formatter<ymd_type, facet_type, charT>::ymd_put(ymd, os, f); } else { // output a special value std::ostreambuf_iterator<charT> coi(os); f.put_special_value(coi, sv); } }
//! Convert to a date to standard string using format policies static std::string date_to_string(date_type d) { typedef typename date_type::ymd_type ymd_type; if (d.is_not_a_date()) { return format_type::not_a_date(); } if (d.is_neg_infinity()) { return format_type::neg_infinity(); } if (d.is_pos_infinity()) { return format_type::pos_infinity(); } ymd_type ymd = d.year_month_day(); return ymd_formatter<ymd_type, format_type>::ymd_to_string(ymd); }