blob: 17ff642dc46d2e82fc76c8f1988a39f0be49e0b2 [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> T9 get_time(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>
20struct testbuf
21 : public std::basic_streambuf<CharT>
22{
23 typedef std::basic_string<CharT> string_type;
24 typedef std::basic_streambuf<CharT> base;
25private:
26 string_type str_;
27public:
28
29 testbuf() {}
30 testbuf(const string_type& str)
31 : str_(str)
32 {
33 base::setg(const_cast<CharT*>(str_.data()),
34 const_cast<CharT*>(str_.data()),
35 const_cast<CharT*>(str_.data()) + str_.size());
36 }
37};
38
39int main()
40{
41 {
42 testbuf<char> sb(" Sat Dec 31 23:55:59 2061");
43 std::istream is(&sb);
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000044 is.imbue(std::locale(LOCALE_en_US_UTF_8));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000045 std::tm t = {0};
Eric Fiselier5b34a5f2014-08-12 00:48:56 +000046 is >> std::get_time(&t, "%a %b %d %H:%M:%S %Y");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000047 assert(t.tm_sec == 59);
48 assert(t.tm_min == 55);
49 assert(t.tm_hour == 23);
50 assert(t.tm_mday == 31);
51 assert(t.tm_mon == 11);
52 assert(t.tm_year == 161);
53 assert(t.tm_wday == 6);
54 assert(is.eof());
55 assert(!is.fail());
56 }
57 {
58 testbuf<wchar_t> sb(L" Sat Dec 31 23:55:59 2061");
59 std::wistream is(&sb);
Howard Hinnantc0d0cba2011-10-03 15:23:59 +000060 is.imbue(std::locale(LOCALE_en_US_UTF_8));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000061 std::tm t = {0};
Eric Fiselier5b34a5f2014-08-12 00:48:56 +000062 is >> std::get_time(&t, L"%a %b %d %H:%M:%S %Y");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000063 assert(t.tm_sec == 59);
64 assert(t.tm_min == 55);
65 assert(t.tm_hour == 23);
66 assert(t.tm_mday == 31);
67 assert(t.tm_mon == 11);
68 assert(t.tm_year == 161);
69 assert(t.tm_wday == 6);
70 assert(is.eof());
71 assert(!is.fail());
72 }
73}