1223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow//===----------------------------------------------------------------------===// 2223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow// 3223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow// The LLVM Compiler Infrastructure 4223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow// 5223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow// This file is dual licensed under the MIT and the University of Illinois Open 6223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow// Source Licenses. See LICENSE.TXT for details. 7223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow// 8223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow//===----------------------------------------------------------------------===// 9223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow 101575e3e813f7f7cde31e699802fa1fcf8e84531cAsiri Rathnayake// UNSUPPORTED: c++98, c++03, c++11, c++14 11223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow// <chrono> 12223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow 13223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow// floor 14223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow 15223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow// template <class ToDuration, class Rep, class Period> 16223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow// constexpr 17223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow// ToDuration 18223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow// floor(const duration<Rep, Period>& d); 19223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow 20223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow#include <chrono> 21223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow#include <type_traits> 22223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow#include <cassert> 23223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow 24223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clowtemplate <class ToDuration, class FromDuration> 25223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clowvoid 26223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clowtest(const FromDuration& f, const ToDuration& d) 27223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow{ 28223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow { 29223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow typedef decltype(std::chrono::floor<ToDuration>(f)) R; 30223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow static_assert((std::is_same<R, ToDuration>::value), ""); 31223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow assert(std::chrono::floor<ToDuration>(f) == d); 32223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow } 33223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow} 34223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow 35223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clowint main() 36223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow{ 37223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow// 7290000ms is 2 hours, 1 minute, and 30 seconds 38223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow test(std::chrono::milliseconds( 7290000), std::chrono::hours( 2)); 39223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow test(std::chrono::milliseconds(-7290000), std::chrono::hours(-3)); 40223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow test(std::chrono::milliseconds( 7290000), std::chrono::minutes( 121)); 41223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow test(std::chrono::milliseconds(-7290000), std::chrono::minutes(-122)); 42223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow 43223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow { 44223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow// 9000000ms is 2 hours and 30 minutes 45223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow constexpr std::chrono::hours h1 = std::chrono::floor<std::chrono::hours>(std::chrono::milliseconds(9000000)); 46223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow static_assert(h1.count() == 2, ""); 47223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow constexpr std::chrono::hours h2 = std::chrono::floor<std::chrono::hours>(std::chrono::milliseconds(-9000000)); 48223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow static_assert(h2.count() == -3, ""); 49223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow } 50223df2ef0f543f7fef9270b3b34b9c73c869a006Marshall Clow} 51