22 #ifndef _DATETIME_HPP_
23 #define _DATETIME_HPP_
25 #include <boost/date_time/local_time/local_time.hpp>
26 #include <boost/math/special_functions/modf.hpp>
28 namespace bdt = boost::date_time;
29 namespace bpt = boost::posix_time;
30 namespace blt = boost::local_time;
32 using bpt::from_time_t;
35 using bpt::from_ftime;
38 using boost::gregorian::date;
49 template<
class time_type>
53 typedef typename time_type::date_type date_type;
54 typedef typename time_type::date_duration_type date_duration_type;
55 typedef typename time_type::time_duration_type time_duration_type;
56 using boost::math::modf;
58 static const date_type base_date(1899, Dec, 30);
59 static const time_type base_time(base_date, time_duration_type(0,0,0));
61 int dayOffset, hourOffset, minuteOffset, secondOffset;
62 double fraction = fabs(modf(oa_date, &dayOffset)) * 24;
63 fraction = modf(fraction, &hourOffset) * 60;
64 fraction = modf(fraction, &minuteOffset) * 60;
65 modf(fraction, &secondOffset);
66 time_type t(base_time);
67 t += time_duration_type(hourOffset, minuteOffset, secondOffset);
68 t += date_duration_type(dayOffset);
83 bpt::time_facet* output_facet =
new bpt::time_facet;
84 output_facet->format(format.c_str());
85 std::ostringstream ss;
86 ss.imbue(std::locale(std::locale::classic(), output_facet));
87 return static_cast<std::ostringstream&
>(ss << t).str();
94 blt::local_time_facet* output_facet =
new blt::local_time_facet;
95 output_facet->format(format.c_str());
96 std::ostringstream ss;
97 ss.imbue(std::locale(std::locale::classic(), output_facet));
98 return static_cast<std::ostringstream&
>(ss << t).str();
105 bpt::time_facet* output_facet =
new bpt::time_facet;
106 output_facet->format(format.c_str());
107 std::ostringstream ss;
108 ss.imbue(std::locale(std::locale::classic(), output_facet));
109 return static_cast<std::ostringstream&
>(ss << t).str();
116 blt::local_time_input_facet* input_facet =
new blt::local_time_input_facet;
117 input_facet->format(format.c_str());
118 std::istringstream ss(t);
119 ss.imbue(std::locale(std::locale::classic(), input_facet));
121 blt::local_date_time result(bdt::not_a_date_time);
150 blt::local_time_input_facet* input_facet =
new blt::local_time_input_facet;
151 input_facet->format(
"%Y-%m-%dT%H:%M:%SZ");
152 std::stringstream ss(t);
153 ss.imbue(std::locale(std::locale::classic(), input_facet));
154 blt::local_date_time result(bdt::not_a_date_time);
156 return blt::local_date_time(result.utc_time(), blt::time_zone_ptr());
164 #endif // _DATETIME_HPP_