blob: 52a98a1b5688c9aaeaf8f29ed7ca83971c8c7a45 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
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 Clow83e2c4d2013-01-05 03:21:01 +000017#include "platform_support.h" // locale name macros
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000018
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000019template <class CharT>
20class testbuf
21 : public std::basic_streambuf<CharT>
22{
23 typedef std::basic_streambuf<CharT> base;
24 std::basic_string<CharT> str_;
25public:
26 testbuf()
27 {
28 }
29
30 std::basic_string<CharT> str() const
31 {return std::basic_string<CharT>(base::pbase(), base::pptr());}
32
33protected:
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
51int main()
52{
53 {
54 testbuf<char> sb;
55 std::ostream os(&sb);
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000056 os.imbue(std::locale(LOCALE_en_US_UTF_8));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000057 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 Fiselier5b34a5f2014-08-12 00:48:56 +000065 t.tm_isdst = 0;
66 os << std::put_time(&t, "%a %b %d %H:%M:%S %Y");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000067 assert(sb.str() == "Sat Dec 31 23:55:59 2061");
68 }
69 {
70 testbuf<wchar_t> sb;
71 std::wostream os(&sb);
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000072 os.imbue(std::locale(LOCALE_en_US_UTF_8));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000073 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 Fiselier5b34a5f2014-08-12 00:48:56 +000081 os << std::put_time(&t, L"%a %b %d %H:%M:%S %Y");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000082 assert(sb.str() == L"Sat Dec 31 23:55:59 2061");
83 }
84}