Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <iomanip> |
| 11 | |
| 12 | // template <class charT> T10 put_time(const struct tm* tmb, const charT* fmt); |
| 13 | |
| 14 | #include <iomanip> |
| 15 | #include <cassert> |
| 16 | |
Marshall Clow | 83e2c4d | 2013-01-05 03:21:01 +0000 | [diff] [blame] | 17 | #include "platform_support.h" // locale name macros |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 18 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 19 | template <class CharT> |
| 20 | class testbuf |
| 21 | : public std::basic_streambuf<CharT> |
| 22 | { |
| 23 | typedef std::basic_streambuf<CharT> base; |
| 24 | std::basic_string<CharT> str_; |
| 25 | public: |
| 26 | testbuf() |
| 27 | { |
| 28 | } |
| 29 | |
| 30 | std::basic_string<CharT> str() const |
| 31 | {return std::basic_string<CharT>(base::pbase(), base::pptr());} |
| 32 | |
| 33 | protected: |
| 34 | |
| 35 | virtual typename base::int_type |
| 36 | overflow(typename base::int_type __c = base::traits_type::eof()) |
| 37 | { |
| 38 | if (__c != base::traits_type::eof()) |
| 39 | { |
| 40 | int n = str_.size(); |
| 41 | str_.push_back(__c); |
| 42 | str_.resize(str_.capacity()); |
| 43 | base::setp(const_cast<CharT*>(str_.data()), |
| 44 | const_cast<CharT*>(str_.data() + str_.size())); |
| 45 | base::pbump(n+1); |
| 46 | } |
| 47 | return __c; |
| 48 | } |
| 49 | }; |
| 50 | |
| 51 | int main() |
| 52 | { |
| 53 | { |
| 54 | testbuf<char> sb; |
| 55 | std::ostream os(&sb); |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 56 | os.imbue(std::locale(LOCALE_en_US_UTF_8)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 57 | std::tm t = {0}; |
| 58 | t.tm_sec = 59; |
| 59 | t.tm_min = 55; |
| 60 | t.tm_hour = 23; |
| 61 | t.tm_mday = 31; |
| 62 | t.tm_mon = 11; |
| 63 | t.tm_year = 161; |
| 64 | t.tm_wday = 6; |
Eric Fiselier | 5b34a5f | 2014-08-12 00:48:56 +0000 | [diff] [blame] | 65 | t.tm_isdst = 0; |
| 66 | os << std::put_time(&t, "%a %b %d %H:%M:%S %Y"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 67 | assert(sb.str() == "Sat Dec 31 23:55:59 2061"); |
| 68 | } |
| 69 | { |
| 70 | testbuf<wchar_t> sb; |
| 71 | std::wostream os(&sb); |
Howard Hinnant | c0d0cba | 2011-10-03 15:23:59 +0000 | [diff] [blame] | 72 | os.imbue(std::locale(LOCALE_en_US_UTF_8)); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 73 | std::tm t = {0}; |
| 74 | t.tm_sec = 59; |
| 75 | t.tm_min = 55; |
| 76 | t.tm_hour = 23; |
| 77 | t.tm_mday = 31; |
| 78 | t.tm_mon = 11; |
| 79 | t.tm_year = 161; |
| 80 | t.tm_wday = 6; |
Eric Fiselier | 5b34a5f | 2014-08-12 00:48:56 +0000 | [diff] [blame] | 81 | os << std::put_time(&t, L"%a %b %d %H:%M:%S %Y"); |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 82 | assert(sb.str() == L"Sat Dec 31 23:55:59 2061"); |
| 83 | } |
| 84 | } |