forked from HowardHinnant/date
Refine decision to use the std::chrono rounding modes
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[](https://gitter.im/HowardHinnant/date?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
[](https://gitter.im/HowardHinnant/date?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
|
|
||||||
_**[Try it out on wandbox!](http://melpon.org/wandbox/permlink/zKiDqIUK0XwePf7Y)**_
|
_**[Try it out on wandbox!](http://melpon.org/wandbox/permlink/lb6FHxHyQ1V9eCLm)**_
|
||||||
|
|
||||||
This is actually several separate C++11/C++14 libraries:
|
This is actually several separate C++11/C++14 libraries:
|
||||||
|
|
||||||
|
19
date.h
19
date.h
@@ -963,8 +963,19 @@ trunc(const std::chrono::duration<Rep, Period>& d)
|
|||||||
return To{detail::trunc(std::chrono::duration_cast<To>(d).count())};
|
return To{detail::trunc(std::chrono::duration_cast<To>(d).count())};
|
||||||
}
|
}
|
||||||
|
|
||||||
// VS Update 2 provides floor, ceil, round, abs in chrono.
|
#ifndef HAS_CHRONO_ROUNDING
|
||||||
#if (defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023918) || __cplusplus <= 201402
|
# if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023918
|
||||||
|
# define HAS_CHRONO_ROUNDING 1
|
||||||
|
# elif defined(__cpp_lib_chrono) && __cplusplus > 201402 && __cpp_lib_chrono >= 201510
|
||||||
|
# define HAS_CHRONO_ROUNDING 1
|
||||||
|
# elif defined(_LIBCPP_VERSION) && __cplusplus > 201402 && _LIBCPP_VERSION >= 3800
|
||||||
|
# define HAS_CHRONO_ROUNDING 1
|
||||||
|
# else
|
||||||
|
# define HAS_CHRONO_ROUNDING 0
|
||||||
|
# endif
|
||||||
|
#endif // HAS_CHRONO_ROUNDING
|
||||||
|
|
||||||
|
#if HAS_CHRONO_ROUNDING == 0
|
||||||
|
|
||||||
// round down
|
// round down
|
||||||
template <class To, class Rep, class Period>
|
template <class To, class Rep, class Period>
|
||||||
@@ -1061,14 +1072,14 @@ ceil(const std::chrono::time_point<Clock, FromDuration>& tp)
|
|||||||
return time_point<Clock, To>{ceil<To>(tp.time_since_epoch())};
|
return time_point<Clock, To>{ceil<To>(tp.time_since_epoch())};
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // (defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023918) || __cplusplus <= 201402
|
#else // HAS_CHRONO_ROUNDING == 1
|
||||||
|
|
||||||
using std::chrono::floor;
|
using std::chrono::floor;
|
||||||
using std::chrono::ceil;
|
using std::chrono::ceil;
|
||||||
using std::chrono::round;
|
using std::chrono::round;
|
||||||
using std::chrono::abs;
|
using std::chrono::abs;
|
||||||
|
|
||||||
#endif // (defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023918) || __cplusplus <= 201402
|
#endif // HAS_CHRONO_ROUNDING
|
||||||
|
|
||||||
// trunc towards zero
|
// trunc towards zero
|
||||||
template <class To, class Clock, class FromDuration>
|
template <class To, class Clock, class FromDuration>
|
||||||
|
Reference in New Issue
Block a user