From e26fd2ed98c96a192de4dbd6358ebd6764eb2836 Mon Sep 17 00:00:00 2001 From: Jeff Garland Date: Tue, 3 Dec 2019 17:06:28 -0700 Subject: [PATCH] pull develop to master for boost 1.72 (#117) * Synchronize each miscrosec test to the next second (#109) * Synchronize each miscrosec test to the next second The aim is to avoid false positives in test_microsec when the seconds, minutes or hours change during time read between the second_clock and the microsec_clock. * Improved readability of the microcec_time_clock test * Improve performance of adding and subtracting time durations from a ptime. (#99) Modifying ptime objects by adding and subtracting time durations was inefficient because it extracted the date and time of day and then re-constructed a ptime using the date and modified time of day. This can be avoided by using the existing time_system utilities which perform the operation by adjusting the number of ticks. Performance is improved by a factor of 48 on my system. * Update CI Scripts * Add time_duration helper functions: (#113) 1. is_positive() - Return boolean value to indicate whether or not time duration is positive. 2. is_zero() - Return boolean value to indicate whether or not time duration is zero. 3. abs() - Return a time_duration which is the absolute value of time duration. Added documentation for these helper functions and improved existing documentation to indicate constness, return values or static functions. * Cease dependence on MPL (#115) --- .travis.yml | 167 +++++++++++------- appveyor.yml | 84 +++++---- example/gregorian/find_last_day_of_months.cpp | 4 +- example/local_time/seconds_since_epoch.cpp | 4 +- include/boost/date_time/constrained_value.hpp | 6 +- include/boost/date_time/time.hpp | 4 +- include/boost/date_time/time_duration.hpp | 16 ++ test/gregorian/testdate_input_facet.cpp | 4 +- test/posix_time/testduration.cpp | 12 +- test/posix_time/testmicrosec_time_clock.cpp | 145 +++++++++------ xmldoc/time_duration.xml | 61 +++++-- 11 files changed, 329 insertions(+), 178 deletions(-) diff --git a/.travis.yml b/.travis.yml index 838e8ede3..6fc7c85d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,14 @@ # Copyright 2016 Peter Dimov -# Copyright 2017, 2018 James E. King III +# Copyright 2017 - 2019 James E. King III # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) # # Generic Travis CI build script for boostorg repositories -# See: https://github.com/jeking3/boost-ci +# See: https://github.com/boostorg/boost-ci # # Instructions for customizing this script for your library: -# +# # 1. Customize the compilers and language levels you want in the 'jobs'. # 2. If you have more than include/, src/, test/, example/, examples/, or # tools/ directories, modify your Travis CI project and add the environment @@ -22,21 +22,19 @@ # # That's it - the scripts will do everything else for you. -sudo: false -dist: trusty +dist: xenial language: cpp env: global: # see: http://www.boost.org/build/doc/html/bbv2/overview/invocation.html#bbv2.overview.invocation.properties - # to use the default for a given environment, comment it out; recommend you build debug and release however.. # - B2_ADDRESS_MODEL=address-model=64,32 # - B2_LINK=link=shared,static # - B2_THREADING=threading=multi,single - - B2_VARIANT=variant=release,debug + - B2_VARIANT=variant=release install: - - git clone https://github.com/jeking3/boost-ci.git boost-ci + - git clone https://github.com/boostorg/boost-ci.git boost-ci - cp -pr boost-ci/ci boost-ci/.codecov.yml . - source ci/travis/install.sh @@ -46,12 +44,16 @@ addons: - binutils-gold - gdb - libc6-dbg - + branches: only: - - develop - master - + - develop + - /bugfix\/.*/ + - /feature\/.*/ + - /fix\/.*/ + - /pr\/.*/ + script: - cd $BOOST_ROOT/libs/$SELF - ci/travis/build.sh @@ -67,95 +69,143 @@ script: # anchors: - clang-34: &clang-34 { apt: { packages: [ "clang-3.4" ], sources: [ "llvm-toolchain-trusty-3.4" ] } } clang-38: &clang-38 { apt: { packages: [ "clang-3.8", - "libstdc++-6-dev" ], sources: [ "llvm-toolchain-trusty-3.8", + "libstdc++-6-dev" ], sources: [ "llvm-toolchain-xenial-3.8", "ubuntu-toolchain-r-test" ] } } clang-4: &clang-4 { apt: { packages: [ "clang-4.0", - "libstdc++-6-dev" ], sources: [ "llvm-toolchain-trusty-4.0", + "libstdc++-6-dev" ], sources: [ "llvm-toolchain-xenial-4.0", "ubuntu-toolchain-r-test" ] } } clang-5: &clang-5 { apt: { packages: [ "clang-5.0", - "libstdc++-7-dev" ], sources: [ "llvm-toolchain-trusty-5.0", + "libstdc++-7-dev" ], sources: [ "llvm-toolchain-xenial-5.0", "ubuntu-toolchain-r-test" ] } } clang-6: &clang-6 { apt: { packages: [ "clang-6.0", + "libc6-dbg", + "libc++-dev", + "libstdc++-8-dev" ], sources: [ "llvm-toolchain-xenial-6.0", + "ubuntu-toolchain-r-test" ] } } + clang-7: &clang-7 { apt: { packages: [ "clang-7", + "libc6-dbg", "libc++-dev", - "libstdc++-8-dev", - "valgrind" ], sources: [ "llvm-toolchain-trusty-6.0", + "libstdc++-8-dev" ], sources: [ "llvm-toolchain-xenial-7", "ubuntu-toolchain-r-test" ] } } - gcc-44: &gcc-44 { apt: { packages: [ "g++-4.4" ], sources: [ "ubuntu-toolchain-r-test" ] } } - gcc-46: &gcc-46 { apt: { packages: [ "g++-4.6" ], sources: [ "ubuntu-toolchain-r-test" ] } } - gcc-48: &gcc-48 { apt: { packages: [ "g++-4.8" ], sources: [ "ubuntu-toolchain-r-test" ] } } - gcc-5: &gcc-5 { apt: { packages: [ "g++-5" ], sources: [ "ubuntu-toolchain-r-test" ] } } + clang-8: &clang-8 { apt: { packages: [ "clang-8", + "libc6-dbg", + "libc++-dev", + "libstdc++-8-dev" ], sources: [ "llvm-toolchain-xenial-8", + "ubuntu-toolchain-r-test" ] } } + gcc-48: &gcc-48 { apt: { packages: [ "g++-4.8" ] } } + gcc-49: &gcc-49 { apt: { packages: [ "g++-4.9" ], sources: [ "ubuntu-toolchain-r-test" ] } } + gcc-5: &gcc-5 { apt: { packages: [ "g++-5" ] } } gcc-6: &gcc-6 { apt: { packages: [ "g++-6" ], sources: [ "ubuntu-toolchain-r-test" ] } } gcc-7: &gcc-7 { apt: { packages: [ "g++-7" ], sources: [ "ubuntu-toolchain-r-test" ] } } gcc-8: &gcc-8 { apt: { packages: [ "g++-8" ], sources: [ "ubuntu-toolchain-r-test" ] } } + gcc-9: &gcc-9 { apt: { packages: [ "g++-9" ], sources: [ "ubuntu-toolchain-r-test" ] } } jobs: allow_failures: + # https://github.com/boostorg/date_time/issues/111 - env: - - COPY="all the environment settings from your job" + - COMMENT=ubsan + - B2_VARIANT=variant=debug + - B2_TOOLSET=gcc-8 + - B2_CXXSTD=03,11,14 + - B2_CXXFLAGS="undefined-sanitizer=norecover" + - B2_DEFINES="define=BOOST_NO_STRESS_TEST=1" + - B2_LINKFLAGS="linkflags=-fuse-ld=gold" + - UBSAN_OPTIONS=print_stacktrace=1 include: # libstdc++ - - { os: "linux", env: [ "TOOLSET=gcc-4.4", "CXXSTD=98,0x" ], addons: *gcc-44 } - - { os: "linux", env: [ "TOOLSET=gcc-4.6", "CXXSTD=03,0x" ], addons: *gcc-46 } - - { os: "linux", env: [ "TOOLSET=gcc-4.8", "CXXSTD=03,11" ], addons: *gcc-48 } - - { os: "linux", env: [ "TOOLSET=gcc-5", "CXXSTD=03,11" ], addons: *gcc-5 } - - { os: "linux", env: [ "TOOLSET=gcc-6", "CXXSTD=03,11,14" ], addons: *gcc-6 } - - { os: "linux", env: [ "TOOLSET=gcc-7", "CXXSTD=03,11,14,17" ], addons: *gcc-7 } - - { os: "linux", env: [ "TOOLSET=gcc-8", "CXXSTD=03,11,14,17,2a" ], addons: *gcc-8 } - - { os: "linux", env: [ "TOOLSET=clang-3.4", "CXXSTD=03,11" ], addons: *clang-34 } - - { os: "linux", env: [ "TOOLSET=clang-3.8", "CXXSTD=03,11,14" ], addons: *clang-38 } - - { os: "linux", env: [ "TOOLSET=clang-4.0", "CXXSTD=03,11,14" ], addons: *clang-4 } - - { os: "linux", env: [ "TOOLSET=clang-5.0", "CXXSTD=03,11,14,17" ], addons: *clang-5 } - - { os: "linux", env: [ "TOOLSET=clang-6.0", "CXXSTD=03,11,14,17,2a" ], addons: *clang-6 } + - { os: "linux", dist: "trusty", # xenial has libstdc++ from gcc 5.4.0 with newer ABI + env: [ "B2_TOOLSET=gcc-4.8", "B2_CXXSTD=03,11" ], addons: *gcc-48 } + - { os: "linux", dist: "trusty", # xenial has libstdc++ from gcc 5.4.0 with newer ABI + env: [ "B2_TOOLSET=gcc-4.9", "B2_CXXSTD=03,11" ], addons: *gcc-49 } + - { os: "linux", env: [ "B2_TOOLSET=gcc-5", "B2_CXXSTD=03,11" ], addons: *gcc-5 } + - { os: "linux", env: [ "B2_TOOLSET=gcc-6", "B2_CXXSTD=11,14" ], addons: *gcc-6 } + - { os: "linux", env: [ "B2_TOOLSET=gcc-7", "B2_CXXSTD=14,17" ], addons: *gcc-7 } + - { os: "linux", env: [ "B2_TOOLSET=gcc-8", "B2_CXXSTD=17,2a" ], addons: *gcc-8 } + - { os: "linux", env: [ "B2_TOOLSET=gcc-9", "B2_CXXSTD=17,2a" ], addons: *gcc-9 } + - { os: "linux", dist: "trusty", # xenial has libstdc++ from gcc 5.4.0 with newer ABI + env: [ "B2_TOOLSET=clang-3.8", "B2_CXXSTD=03,11" ], addons: *clang-38 } + - { os: "linux", env: [ "B2_TOOLSET=clang-4.0", "B2_CXXSTD=11,14" ], addons: *clang-4 } + - { os: "linux", env: [ "B2_TOOLSET=clang-5.0", "B2_CXXSTD=11,14" ], addons: *clang-5 } + - { os: "linux", env: [ "B2_TOOLSET=clang-6.0", "B2_CXXSTD=14,17" ], addons: *clang-6 } + - { os: "linux", env: [ "B2_TOOLSET=clang-7", "B2_CXXSTD=17,2a" ], addons: *clang-7 } + - { os: "linux", env: [ "B2_TOOLSET=clang-8", "B2_CXXSTD=17,2a" ], addons: *clang-8 } + # libc++ - - { os: "linux", env: [ "TOOLSET=clang-6.0", "CXXSTD=03,11,14,17,2a", - "CXXFLAGS=-stdlib=libc++" ], addons: *clang-6 } - # the rvm environment on osx is taking over basic commands like "cd" and breaking things! - # - { os: "osx" , env: [ "COMMENT=libc++", - # "TOOLSET=clang", "CXXSTD=03,11,14" ] } + - { os: "linux", env: [ "B2_TOOLSET=clang-6.0", "B2_CXXSTD=03,11,14", + "B2_CXXFLAGS=-stdlib=libc++" ], addons: *clang-6 } + - { os: "osx" , env: [ "B2_TOOLSET=clang", "B2_CXXSTD=03,11,17" ] } + + # to enable Intel ICC define INTEL_ICC_SERIAL_NUMBER and the following: + # - { os: "linux", env: [ "B2_TOOLSET=intel-linux", "B2_CXXSTD=11,14,17" ], addons: *gcc-7, + # script: cd $BOOST_ROOT/libs/$SELF && ci/travis/intelicc.sh } - os: linux - env: + env: - COMMENT=codecov.io - - TOOLSET=gcc-7 - - DEFINES="define=BOOST_NO_STRESS_TEST=1" - addons: *gcc-7 + - B2_CXXSTD=03,11 + - B2_TOOLSET=gcc-8 + - B2_DEFINES="define=BOOST_NO_STRESS_TEST=1" + addons: *gcc-8 script: - - pushd /tmp && git clone https://github.com/linux-test-project/lcov.git && export PATH=/tmp/lcov/bin:$PATH && which lcov && lcov --version && popd - cd $BOOST_ROOT/libs/$SELF - ci/travis/codecov.sh - os: linux env: - - COMMENT=cppcheck - script: - - cd $BOOST_ROOT/libs/$SELF - - ci/travis/cppcheck.sh + - COMMENT=asan + - B2_VARIANT=variant=debug + - B2_TOOLSET=gcc-8 + - B2_CXXSTD=03,11,14 + - B2_CXXFLAGS="address-sanitizer=norecover" + - B2_DEFINES="define=BOOST_NO_STRESS_TEST=1" + addons: *gcc-8 + + - os: linux + env: + - COMMENT=tsan + - B2_VARIANT=variant=debug + - B2_TOOLSET=gcc-8 + - B2_CXXSTD=03,11,14 + - B2_CXXFLAGS="thread-sanitizer=norecover" + - B2_DEFINES="define=BOOST_NO_STRESS_TEST=1" + addons: *gcc-8 - os: linux env: - COMMENT=ubsan - B2_VARIANT=variant=debug - - TOOLSET=gcc-8 - - CXXSTD=03,11,14,17,2a - - DEFINES="define=BOOST_NO_STRESS_TEST=1" - - CXXFLAGS="cxxflags=-fno-omit-frame-pointer cxxflags=-fsanitize=undefined cxxflags=-fno-sanitize-recover=undefined" - - LINKFLAGS="linkflags=-fsanitize=undefined linkflags=-fno-sanitize-recover=undefined linkflags=-fuse-ld=gold" + - B2_TOOLSET=gcc-8 + - B2_CXXSTD=03,11,14 + - B2_CXXFLAGS="undefined-sanitizer=norecover" + - B2_DEFINES="define=BOOST_NO_STRESS_TEST=1" + # https://github.com/boostorg/build/issues/451 using the gold linker to work around an issue + - B2_LINKFLAGS="linkflags=-fuse-ld=gold" - UBSAN_OPTIONS=print_stacktrace=1 addons: *gcc-8 - os: linux env: - COMMENT=valgrind - - TOOLSET=clang-6.0 - - CXXSTD=03,11,14,17,2a - - DEFINES="define=BOOST_NO_STRESS_TEST=1" + - B2_TOOLSET=clang-6.0 + - B2_CXXSTD=03,11,14 + - B2_DEFINES="define=BOOST_NO_STRESS_TEST=1" - B2_VARIANT=variant=debug - - TESTFLAGS=testing.launcher=valgrind + - B2_TESTFLAGS=testing.launcher=valgrind - VALGRIND_OPTS=--error-exitcode=1 addons: *clang-6 + script: + - cd $BOOST_ROOT/libs/$SELF + - ci/travis/valgrind.sh + + # - os: linux + # env: + # - COMMENT=cppcheck + # script: + # - cd $BOOST_ROOT/libs/$SELF + # - ci/travis/cppcheck.sh #################### Jobs to run on pushes to master, develop ################### @@ -164,8 +214,7 @@ jobs: if: (env(COVERITY_SCAN_NOTIFICATION_EMAIL) IS present) AND (branch IN (develop, master)) AND (type IN (cron, push)) env: - COMMENT="Coverity Scan" - - TOOLSET=gcc-7 - addons: *gcc-7 + - B2_TOOLSET=clang script: - cd $BOOST_ROOT/libs/$SELF - ci/travis/coverity.sh diff --git a/appveyor.yml b/appveyor.yml index afcb1794c..01985bde8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,16 +1,16 @@ # Copyright 2016, 2017 Peter Dimov -# Copyright (C) 2017, 2018 James E. King III +# Copyright (C) 2017 - 2019 James E. King III # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) # # Generic Appveyor build script for boostorg repositories -# See: https://github.com/jeking3/boost-ci/ +# See: https://github.com/boostorg/boost-ci/ # # Instructions for customizing this script for your library: # # 1. Customize the compilers and language levels you want. -# 2. If you have move than include/, src/, test/, example/, examples/, +# 2. If you have more than include/, src/, test/, example/, examples/, # benchmark/ or tools/ directories, set the environment variable DEPINST. # For example if your build uses code in "bench/" and "fog/" directories: # - DEPINST: --include bench --include fog @@ -25,8 +25,12 @@ shallow_clone: true branches: only: - - develop - master + - develop + - /bugfix\/.*/ + - /feature\/.*/ + - /fix\/.*/ + - /pr\/.*/ matrix: # Adding MAYFAIL to any matrix job allows it to fail but the build stays green: @@ -42,76 +46,91 @@ environment: # B2_ADDRESS_MODEL: address-model=64,32 # B2_LINK: link=shared,static # B2_THREADING: threading=multi,single - B2_VARIANT: variant=release,debug + B2_VARIANT: variant=release matrix: + - FLAVOR: Visual Studio 2019 + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 + B2_ADDRESS_MODEL: address-model=64 + B2_CXXFLAGS: cxxflags=-permissive- + B2_CXXSTD: latest # 2a + B2_TOOLSET: msvc-14.2 + - FLAVOR: Visual Studio 2017 C++2a Strict APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - TOOLSET: msvc-14.1 B2_ADDRESS_MODEL: address-model=64 - CXXFLAGS: cxxflags=-permissive- - CXXSTD: latest # 2a + B2_CXXFLAGS: cxxflags=-permissive- + B2_CXXSTD: latest # 2a + B2_TOOLSET: msvc-14.1 - FLAVOR: Visual Studio 2017 C++17 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - TOOLSET: msvc-14.1 B2_ADDRESS_MODEL: address-model=64 - CXXSTD: 17 + B2_CXXSTD: 17 + B2_TOOLSET: msvc-14.1 + B2_VARIANT: variant=debug - FLAVOR: Visual Studio 2017 C++14 (Default) APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 - TOOLSET: msvc-14.1 B2_ADDRESS_MODEL: address-model=64,32 + B2_TOOLSET: msvc-14.1 + + - FLAVOR: clang-cl + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + B2_ADDRESS_MODEL: address-model=64 + B2_CXXSTD: 11 + B2_TOOLSET: clang-win - FLAVOR: Visual Studio 2015 C++14 (Default) APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 - TOOLSET: msvc-14.0 B2_ADDRESS_MODEL: address-model=64,32 + B2_TOOLSET: msvc-14.0 + B2_VARIANT: variant=debug - FLAVOR: Visual Studio 2010, 2012, 2013 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 - TOOLSET: msvc-10.0,msvc-11.0,msvc-12.0 + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + B2_TOOLSET: msvc-10.0,msvc-11.0,msvc-12.0 - FLAVOR: cygwin (32-bit) APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 ADDPATH: C:\cygwin\bin; B2_ADDRESS_MODEL: address-model=32 - CXXSTD: 03,11 + B2_CXXSTD: 03,11 # https://github.com/boostorg/test/issues/144 - DEFINES: define=_POSIX_C_SOURCE=200112L define=_GLIBCXX_USE_CXX11_ABI=1 - THREADING: threadapi=pthread - CYGWIN_UPDATE: true - TOOLSET: gcc + B2_DEFINES: define=_POSIX_C_SOURCE=200112L + B2_THREADING: threadapi=pthread + B2_TOOLSET: gcc + B2_VARIANT: variant=debug - FLAVOR: cygwin (64-bit) APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 ADDPATH: C:\cygwin64\bin; B2_ADDRESS_MODEL: address-model=64 - CXXSTD: 11,17 + B2_CXXSTD: 11,17 # https://github.com/boostorg/test/issues/144 - DEFINES: define=_POSIX_C_SOURCE=200112L define=__USE_ISOC99 define=_GLIBCXX_USE_CXX11_ABI=1 - THREADING: threadapi=pthread - CYGWIN_UPDATE: true - TOOLSET: gcc + B2_DEFINES: define=_POSIX_C_SOURCE=200112L define=__USE_ISOC99 + B2_THREADING: threadapi=pthread + B2_TOOLSET: gcc - FLAVOR: mingw32 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 ARCH: i686 B2_ADDRESS_MODEL: address-model=32 - CXXSTD: 03,11 + B2_CXXSTD: 03,11 SCRIPT: ci\appveyor\mingw.bat + B2_VARIANT: variant=debug - FLAVOR: mingw64 APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 ARCH: x86_64 B2_ADDRESS_MODEL: address-model=64 - CXXSTD: 11,17 - DEFINES: define=__USE_ISOC99 + B2_CXXSTD: 11,17 + B2_DEFINES: define=__USE_ISOC99 SCRIPT: ci\appveyor\mingw.bat install: - set SELF=%APPVEYOR_PROJECT_NAME:-=_% - - git clone https://github.com/jeking3/boost-ci.git C:\boost-ci + - git clone https://github.com/boostorg/boost-ci.git C:\boost-ci - xcopy /s /e /q /i C:\boost-ci\ci .\ci - ci\appveyor\install.bat @@ -120,10 +139,9 @@ build: off test_script: - set SELF=%APPVEYOR_PROJECT_NAME:-=_% - PATH=%ADDPATH%%PATH% - - IF DEFINED CYGWIN_UPDATE (call libs\%SELF%\ci\appveyor\cygwin-update.bat) - # The definition of TOOLCXX omits CXXSTD= if it was not defined above - - IF NOT DEFINED CXXSTD (SET TOOLCXX=toolset=%TOOLSET%) ELSE (SET TOOLCXX=toolset=%TOOLSET% cxxstd=%CXXSTD%) + # The definition of B2_TOOLCXX omits B2_CXXSTD= if it was not defined above + - IF NOT DEFINED B2_CXXSTD (SET B2_TOOLCXX=toolset=%B2_TOOLSET%) ELSE (SET B2_TOOLCXX=toolset=%B2_TOOLSET% cxxstd=%B2_CXXSTD%) # Echo the complete build command to the build log - - IF NOT DEFINED SCRIPT (ECHO b2 libs/%SELF:\=/% %TOOLCXX% %CXXFLAGS% %DEFINES% %THREADING% %B2_ADDRESS_MODEL% %B2_LINK% %B2_THREADING% %B2_VARIANT% -j3) + - IF NOT DEFINED SCRIPT (ECHO b2 libs/%SELF:\=/% %B2_TOOLCXX% %B2_CXXFLAGS% %B2_DEFINES% %B2_THREADING% %B2_ADDRESS_MODEL% %B2_LINK% %B2_THREADING% %B2_VARIANT% -j3) # Now go build... - - IF DEFINED SCRIPT (call libs\%SELF%\%SCRIPT%) ELSE (b2 libs/%SELF:\=/% %TOOLCXX% %CXXFLAGS% %DEFINES% %THREADING% %B2_ADDRESS_MODEL% %B2_LINK% %B2_THREADING% %B2_VARIANT% -j3) + - IF DEFINED SCRIPT (call libs\%SELF%\%SCRIPT%) ELSE (b2 libs/%SELF:\=/% %B2_TOOLCXX% %B2_CXXFLAGS% %B2_DEFINES% %B2_THREADING% %B2_ADDRESS_MODEL% %B2_LINK% %B2_THREADING% %B2_VARIANT% -j3) diff --git a/example/gregorian/find_last_day_of_months.cpp b/example/gregorian/find_last_day_of_months.cpp index 9e59f208d..b0c3640be 100644 --- a/example/gregorian/find_last_day_of_months.cpp +++ b/example/gregorian/find_last_day_of_months.cpp @@ -24,11 +24,11 @@ main() std::cin >> m; month = greg_month(m); } - catch(bad_year by) { + catch(const bad_year& by) { std::cout << "Invalid Year Entered: " << by.what() << '\n' << "Using minimum values for month and year." << std::endl; } - catch(bad_month bm) { + catch(const bad_month& bm) { std::cout << "Invalid Month Entered" << bm.what() << '\n' << "Using minimum value for month. " << std::endl; } diff --git a/example/local_time/seconds_since_epoch.cpp b/example/local_time/seconds_since_epoch.cpp index 7de79517c..decaf33bb 100644 --- a/example/local_time/seconds_since_epoch.cpp +++ b/example/local_time/seconds_since_epoch.cpp @@ -24,10 +24,10 @@ int main() tz_database tz_db; try { tz_db.load_from_file("../data/date_time_zonespec.csv"); - }catch(data_not_accessible dna) { + }catch(const data_not_accessible& dna) { std::cerr << "Error with time zone data file: " << dna.what() << std::endl; exit(EXIT_FAILURE); - }catch(bad_field_count bfc) { + }catch(const bad_field_count& bfc) { std::cerr << "Error with time zone data file: " << bfc.what() << std::endl; exit(EXIT_FAILURE); } diff --git a/include/boost/date_time/constrained_value.hpp b/include/boost/date_time/constrained_value.hpp index b1122d76d..cba6461ba 100644 --- a/include/boost/date_time/constrained_value.hpp +++ b/include/boost/date_time/constrained_value.hpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include namespace boost { @@ -95,8 +95,8 @@ namespace CV { } }; - typedef typename mpl::if_< - is_base_of< std::exception, exception_type >, + typedef typename conditional< + is_base_of< std::exception, exception_type >::value, exception_type, exception_wrapper >::type actual_exception_type; diff --git a/include/boost/date_time/time.hpp b/include/boost/date_time/time.hpp index 632f10d7f..1eafe8810 100644 --- a/include/boost/date_time/time.hpp +++ b/include/boost/date_time/time.hpp @@ -164,7 +164,7 @@ namespace date_time { } time_type operator+=(const time_duration_type& td) { - time_ = (time_system::get_time_rep(date(), time_of_day() + td)); + time_ = time_system::add_time_duration(time_,td); return time_type(time_); } //! subtract time durations @@ -174,7 +174,7 @@ namespace date_time { } time_type operator-=(const time_duration_type& td) { - time_ = (time_system::get_time_rep(date(), time_of_day() - td)); + time_ = time_system::subtract_time_duration(time_, td); return time_type(time_); } diff --git a/include/boost/date_time/time_duration.hpp b/include/boost/date_time/time_duration.hpp index c52779be5..161ee686c 100644 --- a/include/boost/date_time/time_duration.hpp +++ b/include/boost/date_time/time_duration.hpp @@ -144,10 +144,26 @@ namespace date_time { { return duration_type(ticks_ * (-1)); } + duration_type abs() const + { + if ( is_negative() ) + { + return invert_sign(); + } + return duration_type(ticks_); + } bool is_negative() const { return ticks_ < 0; } + bool is_zero() const + { + return ticks_ == 0; + } + bool is_positive() const + { + return ticks_ > 0; + } bool operator<(const time_duration& rhs) const { return ticks_ < rhs.ticks_; diff --git a/test/gregorian/testdate_input_facet.cpp b/test/gregorian/testdate_input_facet.cpp index c52caa744..d0b9c19cc 100644 --- a/test/gregorian/testdate_input_facet.cpp +++ b/test/gregorian/testdate_input_facet.cpp @@ -77,8 +77,8 @@ int main(){ std::stringstream ss("Mar."); std::istreambuf_iterator sitr(ss), str_end; - date_input_facet* f = new date_input_facet(); - f->get(sitr, str_end, ss, m); + date_input_facet f; + f.get(sitr, str_end, ss, m); check("No extra characters consumed", m == greg_month(Mar) && *sitr == '.'); } diff --git a/test/posix_time/testduration.cpp b/test/posix_time/testduration.cpp index 74a4a8e5b..061089290 100644 --- a/test/posix_time/testduration.cpp +++ b/test/posix_time/testduration.cpp @@ -35,8 +35,18 @@ main() time_duration td3(td1.hours(),td1.minutes(),td1.seconds()); check("total up elements", td1 == td3); td1 = -td1; // td1 == "-1:25:00" + check("invert_sign",td3 == td1.invert_sign()); + check("invert_sign",td1 == td3.invert_sign()); + check("abs",td3 == td1.abs()); + check("abs",td3 == td3.abs()); + check("is_positive",td3.is_positive()); + check("is_positive",!td1.is_positive()); + check("is_negative",td1.is_negative()); + check("is_negative",!td3.is_negative()); + check("is_zero",!td1.is_zero()); + check("is_zero",(td1 - td1).is_zero()); td3 = time_duration(td1.hours(),td1.minutes(),td1.seconds()); - check("total up elements-invered sign", td1 == td3); + check("total up elements-inverted sign", td1 == td3); time_duration t_1(0,1,40); diff --git a/test/posix_time/testmicrosec_time_clock.cpp b/test/posix_time/testmicrosec_time_clock.cpp index e3fa020ff..8ee063736 100644 --- a/test/posix_time/testmicrosec_time_clock.cpp +++ b/test/posix_time/testmicrosec_time_clock.cpp @@ -1,5 +1,5 @@ /* Copyright (c) 2002,2003 CrystalClear Software, Inc. - * Use, modification and distribution is subject to the + * Use, modification and distribution is subject to the * Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) @@ -12,95 +12,125 @@ #include #endif +void +sync_to_next_second() +{ + using namespace boost::posix_time; + + ptime t_prev; + ptime t_now = second_clock::local_time(); + + // Wait the next seconds + do + { + t_prev = t_now; + t_now = second_clock::local_time(); + } while (t_now.time_of_day().seconds() == t_prev.time_of_day().seconds()); + + // Wait 300ms in order to avoid seconds of second_clock > microsec_clock. + t_now = microsec_clock::local_time(); + t_prev = t_now; + do + { + t_now = microsec_clock::local_time(); + } while (t_now - t_prev < milliseconds(300)); + +} + + int -main() +main() { #ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK using namespace boost::posix_time; - // ptime last = boost::date_time::microsec_resolution_clock::local_time(); - ptime last = microsec_clock::local_time(); + std::cout << "Check local time of microsec_clock against second_clock" << std::endl; + ptime last = microsec_clock::local_time(); int max = 30; - int i = 0; - for (i = 0; i -2 - boost::int64_t seconds() + boost::int64_t seconds() const Get the normalized number of second +/-(0..59) (will give unpredictable results if calling time_duration is a special_value). @@ -267,7 +267,7 @@ neg_td.seconds(); // --> -3 - boost::int64_t total_seconds() + boost::int64_t total_seconds() const Get the total number of seconds truncating any fractional seconds (will give unpredictable results if calling time_duration is a special_value). @@ -278,7 +278,7 @@ td.total_seconds(); - boost::int64_t total_milliseconds() + boost::int64_t total_milliseconds() const Get the total number of milliseconds truncating any remaining digits (will give unpredictable results if calling time_duration is a special_value). @@ -291,7 +291,7 @@ td.total_milliseconds(); - boost::int64_t total_microseconds() + boost::int64_t total_microseconds() const Get the total number of microseconds truncating any remaining digits (will give unpredictable results if calling time_duration is a special_value). @@ -304,7 +304,7 @@ td.total_microseconds(); - boost::int64_t total_nanoseconds() + boost::int64_t total_nanoseconds() const Get the total number of nanoseconds truncating any remaining digits (will give unpredictable results if calling time_duration is a special_value). @@ -318,7 +318,7 @@ td.total_nanoseconds(); - boost::int64_t fractional_seconds() + boost::int64_t fractional_seconds() const Get the number of fractional seconds (will give unpredictable results if calling time_duration is a special_value). @@ -327,8 +327,8 @@ td.fractional_seconds(); // --> 1000 - bool is_negative() - True if duration is negative. + bool is_negative() const + True if and only if duration is negative. time_duration td(-1,0,0); @@ -336,16 +336,45 @@ td.is_negative(); // --> true - time_duration invert_sign() - Generate a new duration with the sign inverted/ + bool is_zero() const + True if and only if duration is zero. - time_duration td(-1,0,0); + time_duration td(0,0,0); +td.is_zero(); // --> true + + + + bool is_positive() const + True if and only if duration is positive. + + + time_duration td(1,0,0); +td.is_positive(); // --> true + + + + time_duration invert_sign() const + Generate a new duration with the sign inverted. + + + time_duration td(-1,0,0); td.invert_sign(); // --> 01:00:00 - date_time::time_resolutions resolution() + time_duration abs() const + Generate a new duration with the absolute value of the time duration. + + + time_duration td(-1,0,0); +td.abs(); // --> 01:00:00 + time_duration td(+1,0,0); +td.abs(); // --> 01:00:00 + + + + date_time::time_resolutions time_duration::resolution() Describes the resolution capability of the time_duration class. time_resolutions is an enum of resolution possibilities ranging from seconds to nanoseconds. @@ -353,8 +382,8 @@ td.invert_sign(); // --> 01:00:00 - time_duration::num_fractional_digits() - Returns an unsigned short holding the number of fractional digits the time resolution has. + unsigned short time_duration::num_fractional_digits() + Returns the number of fractional digits the time resolution has. unsigned short secs; @@ -363,7 +392,7 @@ secs = time_duration::num_fractional_digits(); - time_duration::ticks_per_second() + boost::int64_t time_duration::ticks_per_second() Return the number of ticks in a second. For example, if the duration supports nanoseconds then the returned result will be 1,000,000,000 (1e+9). @@ -380,7 +409,7 @@ td.ticks() // --> 1000 - time_duration unit() + time_duration time_duration::unit() Return smallest possible unit of duration type (1 nanosecond).