mirror of
https://github.com/HowardHinnant/date.git
synced 2025-01-14 01:37:57 +08:00
Refine decision to use the std::chrono rounding modes
This commit is contained in:
parent
6cb8d59886
commit
845ce25bb7
@ -1,6 +1,6 @@
|
||||
[![Join the chat at https://gitter.im/HowardHinnant/date](https://badges.gitter.im/HowardHinnant/date.svg)](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:
|
||||
|
||||
|
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())};
|
||||
}
|
||||
|
||||
// VS Update 2 provides floor, ceil, round, abs in chrono.
|
||||
#if (defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023918) || __cplusplus <= 201402
|
||||
#ifndef HAS_CHRONO_ROUNDING
|
||||
# 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
|
||||
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())};
|
||||
}
|
||||
|
||||
#else // (defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023918) || __cplusplus <= 201402
|
||||
#else // HAS_CHRONO_ROUNDING == 1
|
||||
|
||||
using std::chrono::floor;
|
||||
using std::chrono::ceil;
|
||||
using std::chrono::round;
|
||||
using std::chrono::abs;
|
||||
|
||||
#endif // (defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023918) || __cplusplus <= 201402
|
||||
#endif // HAS_CHRONO_ROUNDING
|
||||
|
||||
// trunc towards zero
|
||||
template <class To, class Clock, class FromDuration>
|
||||
|
Loading…
x
Reference in New Issue
Block a user