1 /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
2 * Use, modification and distribution is subject to the
3 * Boost Software License, Version 1.0. (See accompanying
4 * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
8 #include "boost/date_time/posix_time/posix_time.hpp"
9 #include "boost/date_time/microsec_time_clock.hpp"
10 #include "../testfrmwk.hpp"
11 #if defined(BOOST_HAS_FTIME)
18 using namespace boost::posix_time;
21 ptime t_now = second_clock::local_time();
23 // Wait the next seconds
27 t_now = second_clock::local_time();
28 } while (t_now.time_of_day().seconds() == t_prev.time_of_day().seconds());
30 // Wait 300ms in order to avoid seconds of second_clock > microsec_clock.
31 t_now = microsec_clock::local_time();
35 t_now = microsec_clock::local_time();
36 } while (t_now - t_prev < milliseconds(300));
44 #ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK
46 using namespace boost::posix_time;
48 std::cout << "Check local time of microsec_clock against second_clock" << std::endl;
50 ptime last = microsec_clock::local_time();
52 for (int i=0; i<max; i++)
54 // Some systems loop too fast so "last is less" tests fail due to
55 // 'last' & 't2' being equal. These calls slow it down enough to
56 // make 'last' & 't2' different. Moreover, we must wait the next
57 // second to avoid a change in hour, minute or second field
58 // between acquisition of t1 and t2.
59 sync_to_next_second();
61 ptime t1 = second_clock::local_time();
62 std::cout << to_simple_string(t1) << std::endl;
64 ptime t2 = microsec_clock::local_time();
65 std::cout << to_simple_string(t2) << std::endl;
67 check("check equality of hours "
68 "between second_clock and microsec_clock timestamps",
69 t1.time_of_day().hours() == t2.time_of_day().hours());
71 check("check equality of minutes "
72 "between second_clock and microsec_clock timestamps",
73 t1.time_of_day().minutes() == t2.time_of_day().minutes());
75 check("check equality of seconds "
76 "between second_clock and microsec_clock timestamps",
77 t1.time_of_day().seconds() == t2.time_of_day().seconds());
79 check("check equality of date"
80 "between second_clock and microsec_clock timestamps",
81 t1.date() == t2.date());
83 if( !check("check that previous microsec_clock timestamp "
84 "is less than the current", last < t2) ) {
85 std::cout << to_simple_string(last) << " < "
86 << to_simple_string(t2) << std::endl;
93 std::cout << "Check universal time of microsec_clock against second_clock" << std::endl;
95 last = microsec_clock::universal_time();
96 for (int i=0; i<max; i++)
98 // Some systems loop too fast so "last is less" tests fail due to
99 // 'last' & 't2' being equal. These calls slow it down enough to
100 // make 'last' & 't2' different. Moreover, we must wait the next
101 // second to avoid a change in hour, minute or second field
102 // between acquisition of t1 and t2.
103 sync_to_next_second();
105 ptime t1 = second_clock::universal_time();
106 std::cout << to_simple_string(t1) << std::endl;
108 ptime t2 = microsec_clock::universal_time();
109 std::cout << to_simple_string(t2) << std::endl;
111 check("check equality of hours "
112 "between second_clock and microsec_clock timestamps",
113 t1.time_of_day().hours() == t2.time_of_day().hours());
115 check("check equality of minutes "
116 "between second_clock and microsec_clock timestamps",
117 t1.time_of_day().minutes() == t2.time_of_day().minutes());
119 check("check equality of seconds "
120 "between second_clock and microsec_clock timestamps",
121 t1.time_of_day().seconds() == t2.time_of_day().seconds());
123 check("check equality of date"
124 "between second_clock and microsec_clock timestamps",
125 t1.date() == t2.date());
127 if( !check("check that previous microsec_clock timestamp "
128 "is less than the current", last < t2) ) {
129 std::cout << to_simple_string(last) << " < "
130 << to_simple_string(t2) << std::endl;
137 check("Get time of day micro second clock not supported due to inadequate compiler/platform", false);
139 return printTestStats();