|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r80940 - in branches/release: boost/date_time boost/date_time/posix_time libs/date_time/test/gregorian libs/date_time/test/posix_time
From: andrey.semashev_at_[hidden]
Date: 2012-10-10 15:05:04
Author: andysem
Date: 2012-10-10 15:05:03 EDT (Wed, 10 Oct 2012)
New Revision: 80940
URL: http://svn.boost.org/trac/boost/changeset/80940
Log:
Merged changes from trunk. Fixes #3471.
Text files modified:
branches/release/boost/date_time/posix_time/posix_time_config.hpp | 2 +-
branches/release/boost/date_time/time_duration.hpp | 15 +++++++++++++--
branches/release/boost/date_time/time_parsing.hpp | 5 +++--
branches/release/libs/date_time/test/gregorian/testdate.cpp | 7 ++++---
branches/release/libs/date_time/test/posix_time/testclock.cpp | 3 ++-
branches/release/libs/date_time/test/posix_time/testduration.cpp | 11 ++++++++++-
6 files changed, 33 insertions(+), 10 deletions(-)
Modified: branches/release/boost/date_time/posix_time/posix_time_config.hpp
==============================================================================
--- branches/release/boost/date_time/posix_time/posix_time_config.hpp (original)
+++ branches/release/boost/date_time/posix_time/posix_time_config.hpp 2012-10-10 15:05:03 EDT (Wed, 10 Oct 2012)
@@ -81,7 +81,7 @@
{}
//Give duration access to ticks constructor -- hide from users
friend class date_time::time_duration<time_duration, time_res_traits>;
- private:
+ protected:
explicit time_duration(impl_type tick_count) :
date_time::time_duration<time_duration, time_res_traits>(tick_count)
{}
Modified: branches/release/boost/date_time/time_duration.hpp
==============================================================================
--- branches/release/boost/date_time/time_duration.hpp (original)
+++ branches/release/boost/date_time/time_duration.hpp 2012-10-10 15:05:03 EDT (Wed, 10 Oct 2012)
@@ -11,6 +11,7 @@
#include <boost/cstdint.hpp>
#include <boost/operators.hpp>
+#include <boost/static_assert.hpp>
#include <boost/date_time/time_defs.hpp>
#include <boost/date_time/special_defs.hpp>
#include <boost/date_time/compiler_config.hpp>
@@ -265,10 +266,20 @@
class subsecond_duration : public base_duration
{
public:
+ typedef typename base_duration::impl_type impl_type;
typedef typename base_duration::traits_type traits_type;
+
+ private:
+ // To avoid integer overflow we precompute the duration resolution conversion coefficient (ticket #3471)
+ BOOST_STATIC_ASSERT_MSG((traits_type::ticks_per_second >= frac_of_second ? traits_type::ticks_per_second % frac_of_second : frac_of_second % traits_type::ticks_per_second) == 0,\
+ "The base duration resolution must be a multiple of the subsecond duration resolution");
+ BOOST_STATIC_CONSTANT(boost::int64_t, adjustment_ratio = (traits_type::ticks_per_second >= frac_of_second ? traits_type::ticks_per_second / frac_of_second : frac_of_second / traits_type::ticks_per_second));
+
+ public:
explicit subsecond_duration(boost::int64_t ss) :
- base_duration(0,0,0,ss*traits_type::res_adjust()/frac_of_second)
- {}
+ base_duration(impl_type(traits_type::ticks_per_second >= frac_of_second ? ss * adjustment_ratio : ss / adjustment_ratio))
+ {
+ }
};
Modified: branches/release/boost/date_time/time_parsing.hpp
==============================================================================
--- branches/release/boost/date_time/time_parsing.hpp (original)
+++ branches/release/boost/date_time/time_parsing.hpp 2012-10-10 15:05:03 EDT (Wed, 10 Oct 2012)
@@ -154,9 +154,10 @@
std::string& first,
std::string& second)
{
- int sep_pos = static_cast<int>(s.find(sep));
+ std::string::size_type sep_pos = s.find(sep);
first = s.substr(0,sep_pos);
- second = s.substr(sep_pos+1);
+ if (sep_pos!=std::string::npos)
+ second = s.substr(sep_pos+1);
return true;
}
Modified: branches/release/libs/date_time/test/gregorian/testdate.cpp
==============================================================================
--- branches/release/libs/date_time/test/gregorian/testdate.cpp (original)
+++ branches/release/libs/date_time/test/gregorian/testdate.cpp 2012-10-10 15:05:03 EDT (Wed, 10 Oct 2012)
@@ -6,6 +6,7 @@
*/
#include <iostream>
+#include <boost/cstdint.hpp>
#include "boost/date_time/gregorian/gregorian.hpp"
#include "../testfrmwk.hpp"
@@ -228,13 +229,13 @@
// most of this testing is in the gregorian_calendar tests
std::cout << d15.julian_day() << std::endl;
check_equal("check julian day ", d15.julian_day(),
- static_cast<uint32_t>(2232400));
+ static_cast<boost::uint32_t>(2232400));
check_equal("check modjulian day ", d15.modjulian_day(), -167601);
date d16(2004,2,29);
check_equal("check julian day ", d16.julian_day(),
- static_cast<uint32_t>(2453065));
+ static_cast<boost::uint32_t>(2453065));
check_equal("check modjulian day ", d16.modjulian_day(),
- static_cast<uint32_t>(53064));
+ static_cast<boost::uint32_t>(53064));
// most of this testing is in the gregorian_calendar tests
date d31(2000, Jun, 1);
Modified: branches/release/libs/date_time/test/posix_time/testclock.cpp
==============================================================================
--- branches/release/libs/date_time/test/posix_time/testclock.cpp (original)
+++ branches/release/libs/date_time/test/posix_time/testclock.cpp 2012-10-10 15:05:03 EDT (Wed, 10 Oct 2012)
@@ -5,6 +5,7 @@
* Author: Jeff Garland
*/
+#include <boost/config.hpp>
#include "boost/date_time/posix_time/posix_time.hpp"
#include <iostream>
@@ -19,7 +20,7 @@
ptime tu = second_clock::universal_time();
std::cout << to_simple_string(tu) << std::endl;
-#if (defined(_POSIX_TIMERS))
+#if !defined(BOOST_WINDOWS) && defined(_POSIX_TIMERS)
for (int i=0; i < 3; ++i) {
ptime t2 = second_clock::local_time();
std::cout << to_simple_string(t2) << std::endl;
Modified: branches/release/libs/date_time/test/posix_time/testduration.cpp
==============================================================================
--- branches/release/libs/date_time/test/posix_time/testduration.cpp (original)
+++ branches/release/libs/date_time/test/posix_time/testduration.cpp 2012-10-10 15:05:03 EDT (Wed, 10 Oct 2012)
@@ -176,7 +176,16 @@
}
#endif
- time_duration t_11(3600,0,0);
+ // Test for overflows (ticket #3471)
+ {
+ ptime start(boost::gregorian::date(2000, 1, 1));
+ ptime end(boost::gregorian::date(2000, 5, 1));
+ time_duration td = end - start;
+ ptime end2 = start + microseconds(td.total_microseconds());
+ check("microseconds constructor overflow", end == end2);
+ }
+
+ time_duration t_11(3600,0,0);
check("3600 hours ", t_11.hours() == 3600);
check("total seconds 3600 hours", t_11.total_seconds() == 12960000);
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk