Ticket #7546: 7546.patch
File 7546.patch, 10.7 KB (added by , 10 years ago) |
---|
-
boost/chrono/io/time_point_io.hpp
24 24 #include <locale> 25 25 #include <string.h> 26 26 27 #define BOOST_CHRONO_INTERNAL_TIMEGM defined BOOST_WINDOWS && ! defined(__CYGWIN__) 28 //#define BOOST_CHRONO_INTERNAL_TIMEGM 29 27 30 namespace boost 28 31 { 29 32 namespace chrono … … 332 335 333 336 namespace detail 334 337 { 335 #if defined BOOST_ WINDOWS && ! defined(__CYGWIN__)338 #if defined BOOST_CHRONO_INTERNAL_TIMEGM 336 339 int is_leap(int year) 337 340 { 338 341 if(year % 400 == 0) … … 412 415 413 416 timezone tz = get_timezone(os); 414 417 std::locale loc = os.getloc(); 415 time_t t = system_clock::to_time_t(t p);418 time_t t = system_clock::to_time_t(time_point_cast<system_clock::duration>(tp)); 416 419 std::tm tm; 417 420 if (tz == timezone::local) 418 421 { … … 629 632 minutes min = detail::extract_z(i, eof, err, ct); 630 633 if (err & std::ios_base::failbit) goto exit; 631 634 time_t t; 632 #if defined BOOST_ WINDOWS && ! defined(__CYGWIN__)635 #if defined BOOST_CHRONO_INTERNAL_TIMEGM 633 636 t = detail::internal_timegm(&tm); 634 637 #else 635 638 t = timegm(&tm); 636 639 #endif 637 tp = system_clock::from_time_t(t) - min + round<microseconds> (duration<double> (sec)); 640 tp = time_point_cast<Duration>( 641 system_clock::from_time_t(t) - min + round<microseconds> (duration<double> (sec)) 642 ); 638 643 } 639 644 else 640 645 { … … 652 657 } 653 658 It i(is); 654 659 It eof; 655 minu = extract_z(i, eof, err, ct);660 minu = detail::extract_z(i, eof, err, ct); 656 661 if (err & std::ios_base::failbit) goto exit; 657 662 if (fz + 2 != pe) 658 663 { … … 668 673 tm.tm_isdst = -1; 669 674 time_t t; 670 675 if (tz == timezone::utc || fz != pe) 671 #if defined BOOST_WINDOWS && ! defined(__CYGWIN__) 676 { 677 #if defined BOOST_CHRONO_INTERNAL_TIMEGM 672 678 t = detail::internal_timegm(&tm); 673 679 #else 674 680 t = timegm(&tm); 675 681 #endif 682 } 676 683 else 684 { 677 685 t = mktime(&tm); 678 tp = system_clock::from_time_t(t) - minu; 686 } 687 tp = time_point_cast<Duration>( 688 system_clock::from_time_t(t) - minu 689 ); 679 690 } 680 691 } 681 692 BOOST_CATCH (...) -
libs/chrono/test/io/time_point_input.cpp
20 20 BOOST_TEST( (tp == boost::chrono::time_point<Clock, D>(res))); 21 21 } 22 22 23 template <typename D> 24 void test_good_system_clock(std::string str, D res) 25 { 26 typedef boost::chrono::system_clock Clock; 27 28 std::istringstream in(str + boost::chrono::clock_string<Clock, char>::since()); 29 boost::chrono::time_point<Clock, D> tp; 30 in >> tp; 31 BOOST_TEST(in.eof()); 32 BOOST_TEST(!in.fail()); 33 std::cout << "Expected= " << boost::chrono::time_point<Clock, D>(res) << std::endl; 34 std::cout << "Obtained= " << tp << std::endl; 35 BOOST_TEST( (tp == boost::chrono::time_point<Clock, D>(res))); 36 } 23 37 template <typename Clock, typename D> 24 38 void test_fail(const char* str, D) 25 39 { … … 91 105 92 106 } 93 107 108 void check_all_system_clock() 109 { 110 using namespace boost::chrono; 111 using namespace boost; 112 113 //test_good_system_clock ("1970-01-01 02:00:00.000000 +0000", hours(2)); 114 //test_good_system_clock ("5000 hours", hours(5000)); 115 // test_good<Clock> ("5000 minutes", minutes(5000)); 116 // test_good<Clock> ("5000 seconds", seconds(5000)); 117 // test_good<Clock> ("1 seconds", seconds(1)); 118 // test_good<Clock> ("1 second", seconds(1)); 119 // test_good<Clock> ("-1 seconds", seconds(-1)); 120 // test_good<Clock> ("0 second", seconds(0)); 121 // test_good<Clock> ("0 seconds", seconds(0)); 122 // test_good<Clock> ("5000 milliseconds", milliseconds(5000)); 123 // test_good<Clock> ("5000 microseconds", microseconds(5000)); 124 // test_good<Clock> ("5000 nanoseconds", nanoseconds(5000)); 125 // test_good<Clock> ("5000 deciseconds", duration<boost::int_least64_t, deci> (5000)); 126 // test_good<Clock> ("5000 [1/30]seconds", duration<boost::int_least64_t, ratio<1, 30> > (5000)); 127 // 128 // test_good<Clock> ("5000 h", hours(5000)); 129 //#if BOOST_CHRONO_VERSION==2 130 // test_good<Clock>("5000 min", minutes(5000)); 131 //#else 132 // test_good<Clock> ("5000 m", minutes(5000)); 133 //#endif 134 // test_good<Clock> ("5000 s", seconds(5000)); 135 // test_good<Clock> ("5000 ms", milliseconds(5000)); 136 // test_good<Clock> ("5000 ns", nanoseconds(5000)); 137 // test_good<Clock> ("5000 ds", duration<boost::int_least64_t, deci> (5000)); 138 // test_good<Clock> ("5000 [1/30]s", duration<boost::int_least64_t, ratio<1, 30> > (5000)); 139 // 140 // test_good<Clock> ("5000 milliseconds", seconds(5)); 141 // test_good<Clock> ("5 milliseconds", nanoseconds(5000000)); 142 // test_good<Clock> ("4000 ms", seconds(4)); 143 // test_fail<Clock> ("3001 ms", seconds(3)); 144 // test_fail_epoch<Clock> ("3001 ms", seconds(3)); 145 // test_fail_epoch<Clock> ("3001 ms since", seconds(3)); 146 147 } 148 94 149 int main() 95 150 { 96 151 std::cout << "high_resolution_clock=" << std::endl; … … 99 154 std::cout << "steady_clock=" << std::endl; 100 155 check_all<boost::chrono::steady_clock> (); 101 156 #endif 102 //std::cout << "system_clock=";103 //check_all<boost::chrono::system_clock>();157 std::cout << "system_clock="; 158 check_all_system_clock(); 104 159 105 160 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK) 106 161 std::cout << "thread_clock="<< std::endl; -
libs/chrono/test/io/time_point_output.cpp
16 16 boost::chrono::time_point<Clock, D> tp(d); 17 17 out << tp; 18 18 BOOST_TEST(out.good()); 19 //std::cout << "Expected= " << std::string(str) + boost::chrono::clock_string<Clock, char>::since() << std::endl; 20 //std::cout << "Obtained= " << out.str() << std::endl; 19 21 BOOST_TEST( (out.str() == std::string(str) + boost::chrono::clock_string<Clock, char>::since())); 20 22 } 21 23 24 template <typename D> 25 void test_good_prefix_system_clock(const char* str, D d) 26 { 27 typedef boost::chrono::system_clock Clock; 28 29 std::ostringstream out; 30 boost::chrono::time_point<Clock, D> tp(d); 31 out << tp; 32 BOOST_TEST(out.good()); 33 34 std::cout << "Expected= " << str << std::endl; 35 std::cout << "Obtained= " << out.str() << std::endl; 36 BOOST_TEST( (out.str() == std::string(str) )); 37 } 38 22 39 template <typename Clock, typename D> 23 40 void test_good_symbol(const char* str, D d) 24 41 { … … 33 50 BOOST_TEST( (out.str() == std::string(str) + boost::chrono::clock_string<Clock, char>::since())); 34 51 } 35 52 36 #if BOOST_CHRONO_VERSION==2 53 #if BOOST_CHRONO_VERSION>=2 54 template <typename D> 55 void test_good_symbol_system_clock(const char* str, D d) 56 { 57 typedef boost::chrono::system_clock Clock; 58 59 std::ostringstream out; 60 boost::chrono::time_point<Clock, D> tp(d); 61 out << boost::chrono::duration_fmt(boost::chrono::duration_style::symbol) << tp; 62 BOOST_TEST(out.good()); 63 std::cout << "Expected= " << str << std::endl; 64 std::cout << "Obtained= " << out.str() << std::endl; 65 BOOST_TEST( (out.str() == std::string(str) )); 66 } 67 37 68 template<typename Clock, typename D> 38 69 void test_good(const char* str, D d, boost::chrono::duration_style style) 39 70 { … … 43 74 BOOST_TEST(out.good()); 44 75 BOOST_TEST((out.str() == std::string(str)+boost::chrono::clock_string<Clock,char>::since())); 45 76 } 77 78 template<typename D> 79 void test_good_system_clock(const char* str, D d, boost::chrono::duration_style style) 80 { 81 typedef boost::chrono::system_clock Clock; 82 83 std::ostringstream out; 84 boost::chrono::time_point<Clock,D> tp(d); 85 out << boost::chrono::duration_fmt(style) << tp; 86 BOOST_TEST(out.good()); 87 std::cout << "Expected= " << str << std::endl; 88 std::cout << "Obtained= " << out.str() << std::endl; 89 BOOST_TEST((out.str() == std::string(str) )); 90 } 46 91 #endif 47 92 48 93 template <typename Clock> … … 81 126 test_good_symbol<Clock> ("2 [1/30]s", duration<boost::int_least64_t, ratio<1, 30> > (2)); 82 127 } 83 128 129 #if BOOST_CHRONO_VERSION==2 130 void check_all_system_clock() 131 { 132 using namespace boost::chrono; 133 using namespace boost; 134 135 test_good_system_clock("1970-01-01 02:00:00.000000 +0000", hours(2), duration_style::prefix); 136 test_good_system_clock("1970-01-01 02:00:00.000000 +0000", hours(2), duration_style::symbol); 137 138 test_good_prefix_system_clock("1970-01-01 02:00:00.000000 +0000", hours(2)); 139 test_good_prefix_system_clock("1970-01-01 00:02:00.000000 +0000", minutes(2)); 140 test_good_prefix_system_clock("1970-01-01 00:00:02.000000 +0000", seconds(2)); 141 test_good_prefix_system_clock("1970-01-01 00:00:01.000000 +0000", seconds(1)); 142 test_good_prefix_system_clock("1969-12-31 23:59:59.000000 +0000", seconds(-1)); 143 test_good_prefix_system_clock("1970-01-01 00:00:00.000000 +0000", seconds(0)); 144 test_good_prefix_system_clock("1970-01-01 00:00:00.002000 +0000", milliseconds(2)); 145 test_good_prefix_system_clock("1970-01-01 00:00:00.000002 +0000", microseconds(2)); 146 test_good_prefix_system_clock("1970-01-01 00:00:00.000000 +0000", nanoseconds(2)); 147 test_good_prefix_system_clock("1970-01-01 00:00:00.200000 +0000", duration<boost::int_least64_t, deci> (2)); 148 test_good_prefix_system_clock("1970-01-01 00:00:00.066667 +0000", duration<boost::int_least64_t, ratio<1, 30> > (2)); 149 150 test_good_symbol_system_clock("1970-01-01 02:00:00.000000 +0000", hours(2)); 151 test_good_symbol_system_clock("1970-01-01 00:02:00.000000 +0000", minutes(2)); 152 test_good_symbol_system_clock("1970-01-01 00:00:02.000000 +0000", seconds(2)); 153 test_good_symbol_system_clock("1970-01-01 00:00:00.002000 +0000", milliseconds(2)); 154 test_good_symbol_system_clock("1970-01-01 00:00:00.000000 +0000", nanoseconds(2)); 155 test_good_symbol_system_clock("1970-01-01 00:00:00.200000 +0000", duration<boost::int_least64_t, deci> (2)); 156 test_good_symbol_system_clock("1970-01-01 00:00:00.066667 +0000", duration<boost::int_least64_t, ratio<1, 30> > (2)); 157 } 158 #endif 84 159 int main() 85 160 { 86 161 … … 90 165 std::cout << "steady_clock=" << std::endl; 91 166 check_all<boost::chrono::steady_clock> (); 92 167 #endif 93 //std::cout << "system_clock="; 94 //check_all<boost::chrono::system_clock>(); 168 std::cout << "system_clock=" << std::endl; 169 #if BOOST_CHRONO_VERSION==2 170 check_all_system_clock(); 171 #else 172 check_all<boost::chrono::system_clock> (); 173 #endif 95 174 96 175 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK) 97 176 std::cout << "thread_clock="<< std::endl;