Index: boost/chrono/io/time_point_io.hpp =================================================================== --- boost/chrono/io/time_point_io.hpp (revision 81020) +++ boost/chrono/io/time_point_io.hpp (working copy) @@ -24,6 +24,9 @@ #include #include +#define BOOST_CHRONO_INTERNAL_TIMEGM defined BOOST_WINDOWS && ! defined(__CYGWIN__) +//#define BOOST_CHRONO_INTERNAL_TIMEGM + namespace boost { namespace chrono @@ -332,7 +335,7 @@ namespace detail { -#if defined BOOST_WINDOWS && ! defined(__CYGWIN__) +#if defined BOOST_CHRONO_INTERNAL_TIMEGM int is_leap(int year) { if(year % 400 == 0) @@ -412,7 +415,7 @@ timezone tz = get_timezone(os); std::locale loc = os.getloc(); - time_t t = system_clock::to_time_t(tp); + time_t t = system_clock::to_time_t(time_point_cast(tp)); std::tm tm; if (tz == timezone::local) { @@ -629,12 +632,14 @@ minutes min = detail::extract_z(i, eof, err, ct); if (err & std::ios_base::failbit) goto exit; time_t t; -#if defined BOOST_WINDOWS && ! defined(__CYGWIN__) +#if defined BOOST_CHRONO_INTERNAL_TIMEGM t = detail::internal_timegm(&tm); #else t = timegm(&tm); #endif - tp = system_clock::from_time_t(t) - min + round (duration (sec)); + tp = time_point_cast( + system_clock::from_time_t(t) - min + round (duration (sec)) + ); } else { @@ -652,7 +657,7 @@ } It i(is); It eof; - minu = extract_z(i, eof, err, ct); + minu = detail::extract_z(i, eof, err, ct); if (err & std::ios_base::failbit) goto exit; if (fz + 2 != pe) { @@ -668,14 +673,20 @@ tm.tm_isdst = -1; time_t t; if (tz == timezone::utc || fz != pe) -#if defined BOOST_WINDOWS && ! defined(__CYGWIN__) + { +#if defined BOOST_CHRONO_INTERNAL_TIMEGM t = detail::internal_timegm(&tm); #else t = timegm(&tm); #endif + } else + { t = mktime(&tm); - tp = system_clock::from_time_t(t) - minu; + } + tp = time_point_cast( + system_clock::from_time_t(t) - minu + ); } } BOOST_CATCH (...) Index: libs/chrono/test/io/time_point_input.cpp =================================================================== --- libs/chrono/test/io/time_point_input.cpp (revision 81020) +++ libs/chrono/test/io/time_point_input.cpp (working copy) @@ -20,6 +20,20 @@ BOOST_TEST( (tp == boost::chrono::time_point(res))); } +template +void test_good_system_clock(std::string str, D res) +{ + typedef boost::chrono::system_clock Clock; + + std::istringstream in(str + boost::chrono::clock_string::since()); + boost::chrono::time_point tp; + in >> tp; + BOOST_TEST(in.eof()); + BOOST_TEST(!in.fail()); + std::cout << "Expected= " << boost::chrono::time_point(res) << std::endl; + std::cout << "Obtained= " << tp << std::endl; + BOOST_TEST( (tp == boost::chrono::time_point(res))); +} template void test_fail(const char* str, D) { @@ -91,6 +105,47 @@ } +void check_all_system_clock() +{ + using namespace boost::chrono; + using namespace boost; + + //test_good_system_clock ("1970-01-01 02:00:00.000000 +0000", hours(2)); + //test_good_system_clock ("5000 hours", hours(5000)); +// test_good ("5000 minutes", minutes(5000)); +// test_good ("5000 seconds", seconds(5000)); +// test_good ("1 seconds", seconds(1)); +// test_good ("1 second", seconds(1)); +// test_good ("-1 seconds", seconds(-1)); +// test_good ("0 second", seconds(0)); +// test_good ("0 seconds", seconds(0)); +// test_good ("5000 milliseconds", milliseconds(5000)); +// test_good ("5000 microseconds", microseconds(5000)); +// test_good ("5000 nanoseconds", nanoseconds(5000)); +// test_good ("5000 deciseconds", duration (5000)); +// test_good ("5000 [1/30]seconds", duration > (5000)); +// +// test_good ("5000 h", hours(5000)); +//#if BOOST_CHRONO_VERSION==2 +// test_good("5000 min", minutes(5000)); +//#else +// test_good ("5000 m", minutes(5000)); +//#endif +// test_good ("5000 s", seconds(5000)); +// test_good ("5000 ms", milliseconds(5000)); +// test_good ("5000 ns", nanoseconds(5000)); +// test_good ("5000 ds", duration (5000)); +// test_good ("5000 [1/30]s", duration > (5000)); +// +// test_good ("5000 milliseconds", seconds(5)); +// test_good ("5 milliseconds", nanoseconds(5000000)); +// test_good ("4000 ms", seconds(4)); +// test_fail ("3001 ms", seconds(3)); +// test_fail_epoch ("3001 ms", seconds(3)); +// test_fail_epoch ("3001 ms since", seconds(3)); + +} + int main() { std::cout << "high_resolution_clock=" << std::endl; @@ -99,8 +154,8 @@ std::cout << "steady_clock=" << std::endl; check_all (); #endif - //std::cout << "system_clock="; - //check_all(); + std::cout << "system_clock="; + check_all_system_clock(); #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK) std::cout << "thread_clock="<< std::endl; Index: libs/chrono/test/io/time_point_output.cpp =================================================================== --- libs/chrono/test/io/time_point_output.cpp (revision 81020) +++ libs/chrono/test/io/time_point_output.cpp (working copy) @@ -16,9 +16,26 @@ boost::chrono::time_point tp(d); out << tp; BOOST_TEST(out.good()); + //std::cout << "Expected= " << std::string(str) + boost::chrono::clock_string::since() << std::endl; + //std::cout << "Obtained= " << out.str() << std::endl; BOOST_TEST( (out.str() == std::string(str) + boost::chrono::clock_string::since())); } +template +void test_good_prefix_system_clock(const char* str, D d) +{ + typedef boost::chrono::system_clock Clock; + + std::ostringstream out; + boost::chrono::time_point tp(d); + out << tp; + BOOST_TEST(out.good()); + + std::cout << "Expected= " << str << std::endl; + std::cout << "Obtained= " << out.str() << std::endl; + BOOST_TEST( (out.str() == std::string(str) )); +} + template void test_good_symbol(const char* str, D d) { @@ -33,7 +50,21 @@ BOOST_TEST( (out.str() == std::string(str) + boost::chrono::clock_string::since())); } -#if BOOST_CHRONO_VERSION==2 +#if BOOST_CHRONO_VERSION>=2 +template +void test_good_symbol_system_clock(const char* str, D d) +{ + typedef boost::chrono::system_clock Clock; + + std::ostringstream out; + boost::chrono::time_point tp(d); + out << boost::chrono::duration_fmt(boost::chrono::duration_style::symbol) << tp; + BOOST_TEST(out.good()); + std::cout << "Expected= " << str << std::endl; + std::cout << "Obtained= " << out.str() << std::endl; + BOOST_TEST( (out.str() == std::string(str) )); +} + template void test_good(const char* str, D d, boost::chrono::duration_style style) { @@ -43,6 +74,20 @@ BOOST_TEST(out.good()); BOOST_TEST((out.str() == std::string(str)+boost::chrono::clock_string::since())); } + +template +void test_good_system_clock(const char* str, D d, boost::chrono::duration_style style) +{ + typedef boost::chrono::system_clock Clock; + + std::ostringstream out; + boost::chrono::time_point tp(d); + out << boost::chrono::duration_fmt(style) << tp; + BOOST_TEST(out.good()); + std::cout << "Expected= " << str << std::endl; + std::cout << "Obtained= " << out.str() << std::endl; + BOOST_TEST((out.str() == std::string(str) )); +} #endif template @@ -81,6 +126,36 @@ test_good_symbol ("2 [1/30]s", duration > (2)); } +#if BOOST_CHRONO_VERSION==2 +void check_all_system_clock() +{ + using namespace boost::chrono; + using namespace boost; + + test_good_system_clock("1970-01-01 02:00:00.000000 +0000", hours(2), duration_style::prefix); + test_good_system_clock("1970-01-01 02:00:00.000000 +0000", hours(2), duration_style::symbol); + + test_good_prefix_system_clock("1970-01-01 02:00:00.000000 +0000", hours(2)); + test_good_prefix_system_clock("1970-01-01 00:02:00.000000 +0000", minutes(2)); + test_good_prefix_system_clock("1970-01-01 00:00:02.000000 +0000", seconds(2)); + test_good_prefix_system_clock("1970-01-01 00:00:01.000000 +0000", seconds(1)); + test_good_prefix_system_clock("1969-12-31 23:59:59.000000 +0000", seconds(-1)); + test_good_prefix_system_clock("1970-01-01 00:00:00.000000 +0000", seconds(0)); + test_good_prefix_system_clock("1970-01-01 00:00:00.002000 +0000", milliseconds(2)); + test_good_prefix_system_clock("1970-01-01 00:00:00.000002 +0000", microseconds(2)); + test_good_prefix_system_clock("1970-01-01 00:00:00.000000 +0000", nanoseconds(2)); + test_good_prefix_system_clock("1970-01-01 00:00:00.200000 +0000", duration (2)); + test_good_prefix_system_clock("1970-01-01 00:00:00.066667 +0000", duration > (2)); + + test_good_symbol_system_clock("1970-01-01 02:00:00.000000 +0000", hours(2)); + test_good_symbol_system_clock("1970-01-01 00:02:00.000000 +0000", minutes(2)); + test_good_symbol_system_clock("1970-01-01 00:00:02.000000 +0000", seconds(2)); + test_good_symbol_system_clock("1970-01-01 00:00:00.002000 +0000", milliseconds(2)); + test_good_symbol_system_clock("1970-01-01 00:00:00.000000 +0000", nanoseconds(2)); + test_good_symbol_system_clock("1970-01-01 00:00:00.200000 +0000", duration (2)); + test_good_symbol_system_clock("1970-01-01 00:00:00.066667 +0000", duration > (2)); +} +#endif int main() { @@ -90,8 +165,12 @@ std::cout << "steady_clock=" << std::endl; check_all (); #endif - //std::cout << "system_clock="; - //check_all(); + std::cout << "system_clock=" << std::endl; +#if BOOST_CHRONO_VERSION==2 + check_all_system_clock(); +#else + check_all (); +#endif #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK) std::cout << "thread_clock="<< std::endl;