28 using namespace pwiz::util;
35 template<
typename time_type>
38 typedef typename time_type::date_type date_type;
39 typedef typename time_type::date_duration_type date_duration_type;
40 typedef typename time_type::time_duration_type time_duration_type;
42 if (
os_) *
os_ <<
"OADATE: 0.0 -> " << time_from_OADATE<time_type>(0.0) << endl;
43 unit_assert(time_from_OADATE<time_type>(0.0) == time_type(date_type(1899, bdt::Dec, 30), time_duration_type(0,0,0)));
45 if (
os_) *
os_ <<
"OADATE: 1.0 -> " << time_from_OADATE<time_type>(1.0) << endl;
46 unit_assert(time_from_OADATE<time_type>(1.0) == time_type(date_type(1899, bdt::Dec, 31), time_duration_type(0,0,0)));
48 if (
os_) *
os_ <<
"OADATE: -1.0 -> " << time_from_OADATE<time_type>(-1.0) << endl;
49 unit_assert(time_from_OADATE<time_type>(-1.0) == time_type(date_type(1899, bdt::Dec, 29), time_duration_type(0,0,0)));
51 if (
os_) *
os_ <<
"OADATE: 2.0 -> " << time_from_OADATE<time_type>(2.0) << endl;
52 unit_assert(time_from_OADATE<time_type>(2.0) == time_type(date_type(1900, bdt::Jan, 1), time_duration_type(0,0,0)));
54 if (
os_) *
os_ <<
"OADATE: 2.25 -> " << time_from_OADATE<time_type>(2.25) << endl;
55 unit_assert(time_from_OADATE<time_type>(2.25) == time_type(date_type(1900, bdt::Jan, 1), time_duration_type(6,0,0)));
57 if (
os_) *
os_ <<
"OADATE: -1.25 -> " << time_from_OADATE<time_type>(-1.25) << endl;
58 unit_assert(time_from_OADATE<time_type>(-1.25) == time_type(date_type(1899, bdt::Dec, 29), time_duration_type(6,0,0)));
65 typedef blt::local_date_time datetime;
66 typedef datetime::time_duration_type time;
70 ptime pt = ptime(date(1942, bdt::Apr, 2));
72 if (
os_) *
os_ << pt <<
" -> " << encoded << endl;
75 pt = ptime(date(2011, bdt::Nov, 11));
77 if (
os_) *
os_ << pt <<
" -> " << encoded << endl;
80 pt = ptime(date(2000, bdt::Nov, 11), time(1, 2, 3));
82 if (
os_) *
os_ << pt <<
" -> " << encoded << endl;
85 time elapsed = time(1, 2, 3) - time(0, 0, 3);
87 if (
os_) *
os_ << bpt::to_simple_string(elapsed) <<
" -> " << encoded << endl;
90 elapsed = time(1, 2, 3) - time(0, 1, 2);
92 if (
os_) *
os_ << bpt::to_simple_string(elapsed) <<
" -> " << encoded << endl;
95 elapsed = time(1, 2, 3) - time(1, 2, 3);
97 if (
os_) *
os_ << bpt::to_simple_string(elapsed) <<
" -> " << encoded << endl;
104 typedef blt::local_date_time datetime;
108 encoded =
"1942-04-02";
111 unit_assert(decoded.local_time().date().year() == 1942);
112 unit_assert(decoded.local_time().date().month() == 4);
113 unit_assert(decoded.local_time().date().day() == 2);
115 encoded =
"1400-12-11";
118 unit_assert(decoded.local_time().date().year() == 1400);
119 unit_assert(decoded.local_time().date().month() == 11);
120 unit_assert(decoded.local_time().date().day() == 12);
125 unit_assert(decoded.local_time().time_of_day().hours() == 12);
126 unit_assert(decoded.local_time().time_of_day().minutes() == 42);
127 unit_assert(decoded.local_time().time_of_day().seconds() == 21);
129 encoded =
"16:42:21 on 01-02-2011";
131 if (
os_) *
os_ << encoded <<
" -> " <<
format_date_time(
"%H:%M:%S on %m-%d-%Y", decoded.local_time()) << endl;
132 unit_assert(decoded.local_time().date().year() == 2011);
133 unit_assert(decoded.local_time().date().month() == 1);
134 unit_assert(decoded.local_time().date().day() == 2);
135 unit_assert(decoded.local_time().time_of_day().hours() == 16);
136 unit_assert(decoded.local_time().time_of_day().minutes() == 42);
137 unit_assert(decoded.local_time().time_of_day().seconds() == 21);
144 typedef blt::local_date_time datetime;
145 typedef datetime::time_duration_type time;
148 blt::time_zone_ptr nyc(
new blt::posix_time_zone(
"EST-05:00:00EDT+01:00:00,M4.1.0/02:00:00,M10.5.0/02:00:00"));
149 blt::time_zone_ptr utc;
152 datetime decoded(bdt::not_a_date_time);
155 datetime dt = datetime(ptime(date(1899, bdt::Dec, 30), time(0,0,0)), utc);
157 if (
os_) *
os_ << dt <<
" -> " << encoded << endl;
160 if (
os_) *
os_ << encoded <<
" -> " << decoded << endl;
163 dt = datetime(ptime(date(1999, bdt::Dec, 31), time(23,59,59)), utc);
165 if (
os_) *
os_ << dt <<
" -> " << encoded << endl;
168 if (
os_) *
os_ << encoded <<
" -> " << decoded << endl;
171 dt = datetime(ptime(date(2525, bdt::Jan, 1), time(1,2,3)), utc);
173 if (
os_) *
os_ << dt <<
" -> " << encoded << endl;
176 if (
os_) *
os_ << encoded <<
" -> " << decoded << endl;
179 dt = datetime(ptime(date(1492, bdt::Feb, 3), time(4,5,6)), utc);
181 if (
os_) *
os_ << dt <<
" -> " << encoded << endl;
184 if (
os_) *
os_ << encoded <<
" -> " << decoded << endl;
188 dt = datetime(date(1899, bdt::Dec, 30), time(0,0,0), nyc, datetime::NOT_DATE_TIME_ON_ERROR);
190 if (
os_) *
os_ << dt <<
" -> " << encoded << endl;
193 if (
os_) *
os_ << encoded <<
" -> " << decoded << endl;
196 dt = datetime(date(1999, bdt::Dec, 31), time(23,59,59), nyc, datetime::NOT_DATE_TIME_ON_ERROR);
198 if (
os_) *
os_ << dt <<
" -> " << encoded << endl;
201 if (
os_) *
os_ << encoded <<
" -> " << decoded << endl;
204 dt = datetime(date(2525, bdt::Jan, 1), time(1,2,3), nyc, datetime::NOT_DATE_TIME_ON_ERROR);
206 if (
os_) *
os_ << dt <<
" -> " << encoded << endl;
209 if (
os_) *
os_ << encoded <<
" -> " << decoded << endl;
212 dt = datetime(date(1492, bdt::Jun, 3), time(4,5,6), nyc, datetime::NOT_DATE_TIME_ON_ERROR);
214 if (
os_) *
os_ << dt <<
" -> " << encoded << endl;
223 int main(
int argc,
const char* argv[])
229 if (argc>1 && !strcmp(argv[1],
"-v"))
os_ = &cout;
232 using namespace boost::local_time;
233 *
os_ <<
"DateTimeTest\n";
234 local_time_facet* output_facet =
new local_time_facet;
235 output_facet->format(
"%Y-%m-%d %H:%M:%S %z");
236 os_->imbue(std::locale(std::locale::classic(), output_facet));
238 test_time_from_OADATE<boost::posix_time::ptime>();