| 1 | // |
|---|---|
| 2 | // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) |
| 3 | // |
| 4 | // Distributed under the Boost Software License, Version 1.0. |
| 5 | // https://www.boost.org/LICENSE_1_0.txt |
| 6 | |
| 7 | #include <boost/locale/format.hpp> |
| 8 | #include <boost/locale/formatting.hpp> |
| 9 | #include <boost/locale/generator.hpp> |
| 10 | #include <ctime> |
| 11 | #include <iomanip> |
| 12 | #include <iostream> |
| 13 | #include <sstream> |
| 14 | |
| 15 | #include "boostLocale/test/tools.hpp" |
| 16 | #include "boostLocale/test/unit_test.hpp" |
| 17 | |
| 18 | BOOST_LOCALE_DISABLE_UNREACHABLE_CODE_WARNING |
| 19 | void test_main(int /*argc*/, char** /*argv*/) |
| 20 | { |
| 21 | #ifndef BOOST_LOCALE_WITH_ICU |
| 22 | std::cout << "ICU is not build... Skipping\n"; |
| 23 | return; |
| 24 | #endif |
| 25 | const time_t now = std::time(timer: nullptr); |
| 26 | boost::locale::generator gen; |
| 27 | std::locale::global(loc: gen("en_US.UTF-8")); |
| 28 | |
| 29 | for(int i = 0; i < 366; i++) { |
| 30 | time_t point = now + i * 24 * 3600; |
| 31 | std::stringstream ss; |
| 32 | ss << boost::locale::format("{1,ftime='%H %M %S'}") % point; |
| 33 | int icu_hour = 0, icu_min = 0, icu_sec = 0; |
| 34 | ss >> icu_hour >> icu_min >> icu_sec; |
| 35 | std::tm* tm = localtime_wrap(time: &point); |
| 36 | TEST_EQ(icu_hour, tm->tm_hour); |
| 37 | TEST_EQ(icu_min, tm->tm_min); |
| 38 | TEST_EQ(icu_sec, tm->tm_sec); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | // boostinspect:noascii |
| 43 |
