1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// UNSUPPORTED: c++98, c++03, c++11, c++14 11// <chrono> 12 13// ceil 14 15// template <class ToDuration, class Clock, class Duration> 16// time_point<Clock, ToDuration> 17// ceil(const time_point<Clock, Duration>& t); 18 19#include <chrono> 20#include <type_traits> 21#include <cassert> 22 23template <class FromDuration, class ToDuration> 24void 25test(const FromDuration& df, const ToDuration& d) 26{ 27 typedef std::chrono::system_clock Clock; 28 typedef std::chrono::time_point<Clock, FromDuration> FromTimePoint; 29 typedef std::chrono::time_point<Clock, ToDuration> ToTimePoint; 30 { 31 FromTimePoint f(df); 32 ToTimePoint t(d); 33 typedef decltype(std::chrono::ceil<ToDuration>(f)) R; 34 static_assert((std::is_same<R, ToTimePoint>::value), ""); 35 assert(std::chrono::ceil<ToDuration>(f) == t); 36 } 37} 38 39template<class FromDuration, long long From, class ToDuration, long long To> 40void test_constexpr () 41{ 42 typedef std::chrono::system_clock Clock; 43 typedef std::chrono::time_point<Clock, FromDuration> FromTimePoint; 44 typedef std::chrono::time_point<Clock, ToDuration> ToTimePoint; 45 { 46 constexpr FromTimePoint f{FromDuration{From}}; 47 constexpr ToTimePoint t{ToDuration{To}}; 48 static_assert(std::chrono::ceil<ToDuration>(f) == t, ""); 49 } 50} 51 52 53int main() 54{ 55// 7290000ms is 2 hours, 1 minute, and 30 seconds 56 test(std::chrono::milliseconds( 7290000), std::chrono::hours( 3)); 57 test(std::chrono::milliseconds(-7290000), std::chrono::hours(-2)); 58 test(std::chrono::milliseconds( 7290000), std::chrono::minutes( 122)); 59 test(std::chrono::milliseconds(-7290000), std::chrono::minutes(-121)); 60 61// 9000000ms is 2 hours and 30 minutes 62 test_constexpr<std::chrono::milliseconds, 9000000, std::chrono::hours, 3> (); 63 test_constexpr<std::chrono::milliseconds,-9000000, std::chrono::hours, -2> (); 64 test_constexpr<std::chrono::milliseconds, 9000001, std::chrono::minutes, 151> (); 65 test_constexpr<std::chrono::milliseconds,-9000001, std::chrono::minutes,-150> (); 66 67 test_constexpr<std::chrono::milliseconds, 9000000, std::chrono::seconds, 9000> (); 68 test_constexpr<std::chrono::milliseconds,-9000000, std::chrono::seconds,-9000> (); 69} 70