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// REQUIRES: locale.en_US.UTF-8
11
12// <iomanip>
13
14// template <class charT> T9 get_time(struct tm* tmb, const charT* fmt);
15
16#include <iomanip>
17#include <cassert>
18
19#include "platform_support.h" // locale name macros
20
21template <class CharT>
22struct testbuf
23    : public std::basic_streambuf<CharT>
24{
25    typedef std::basic_string<CharT> string_type;
26    typedef std::basic_streambuf<CharT> base;
27private:
28    string_type str_;
29public:
30
31    testbuf() {}
32    testbuf(const string_type& str)
33        : str_(str)
34    {
35        base::setg(const_cast<CharT*>(str_.data()),
36                   const_cast<CharT*>(str_.data()),
37                   const_cast<CharT*>(str_.data()) + str_.size());
38    }
39};
40
41int main()
42{
43    {
44        testbuf<char> sb("  Sat Dec 31 23:55:59 2061");
45        std::istream is(&sb);
46        is.imbue(std::locale(LOCALE_en_US_UTF_8));
47        std::tm t = {};
48        is >> std::get_time(&t, "%a %b %d %H:%M:%S %Y");
49        assert(t.tm_sec == 59);
50        assert(t.tm_min == 55);
51        assert(t.tm_hour == 23);
52        assert(t.tm_mday == 31);
53        assert(t.tm_mon == 11);
54        assert(t.tm_year == 161);
55        assert(t.tm_wday == 6);
56        assert(is.eof());
57        assert(!is.fail());
58    }
59    {
60        testbuf<wchar_t> sb(L"  Sat Dec 31 23:55:59 2061");
61        std::wistream is(&sb);
62        is.imbue(std::locale(LOCALE_en_US_UTF_8));
63        std::tm t = {};
64        is >> std::get_time(&t, L"%a %b %d %H:%M:%S %Y");
65        assert(t.tm_sec == 59);
66        assert(t.tm_min == 55);
67        assert(t.tm_hour == 23);
68        assert(t.tm_mday == 31);
69        assert(t.tm_mon == 11);
70        assert(t.tm_year == 161);
71        assert(t.tm_wday == 6);
72        assert(is.eof());
73        assert(!is.fail());
74    }
75}
76