void save(Archive & ar, 
          const posix_time::ptime& pt, 
          unsigned int version)
{
  // from_iso_string does not include fractional seconds
  // therefore date and time_duration are used
  typename posix_time::ptime::date_type d = pt.date();
  typename posix_time::ptime::time_duration_type td = pt.time_of_day();
  ar & make_nvp("ptime_date", d);
  ar & make_nvp("ptime_time_duration", td);
}
Beispiel #2
0
String to_http_date(const posix_time::ptime &datetime)
{
    using detail::append_number;

    typedef gregorian::date::ymd_type::year_type::value_type year_type;
    typedef gregorian::date::ymd_type::day_type::value_type day_type;

    String ret;
    ret.reserve(29);
    ret.append([&datetime]() {
            using namespace gregorian;
            switch(datetime.date().day_of_week()) {
            case Monday: return "Mon, ";
            case Tuesday: return "Tue, ";
            case Wednesday: return "Wed, ";
            case Thursday: return "Thu, ";
            case Friday: return "Fri, ";
            case Saturday: return "Sat, ";
            case Sunday: return "Sun, ";
            default:
                throw std::out_of_range("bad day of week");
            }
        }(), 5);

    {
        gregorian::date::ymd_type ymd = datetime.date().year_month_day();

        append_number<String, 2, day_type>(ret, ymd.day);
        ret.push_back(' ');

        switch (ymd.month) {
        case 1: ret.append("Jan ", 4); break;
        case 2: ret.append("Feb ", 4); break;
        case 3: ret.append("Mar ", 4); break;
        case 4: ret.append("Apr ", 4); break;
        case 5: ret.append("May ", 4); break;
        case 6: ret.append("Jun ", 4); break;
        case 7: ret.append("Jul ", 4); break;
        case 8: ret.append("Aug ", 4); break;
        case 9: ret.append("Sep ", 4); break;
        case 10: ret.append("Oct ", 4); break;
        case 11: ret.append("Nov ", 4); break;
        case 12: ret.append("Dec ", 4); break;
        default:
            throw std::out_of_range("bad month");
        }

        append_number<String, 4, year_type>(ret, ymd.year);
    }
    {
        auto time = datetime.time_of_day();
        ret.push_back(' ');
        append_number<String, 2>(ret, time.hours());
        ret.push_back(':');
        append_number<String, 2>(ret, time.minutes());
        ret.push_back(':');
        append_number<String, 2>(ret, time.seconds());
    }
    ret.append(" GMT", 4);
    return ret;
}
Beispiel #3
0
posix_time::ptime ceil(const posix_time::ptime &time,
	const posix_time::time_duration &prec)
{
	return posix_time::ptime(time.date(),
		my::time::ceil(time.time_of_day(), prec));
}