1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// REQUIRES: locale.en_US.UTF-8
10
11// <iomanip>
12
13// template <class charT> T9 get_time(struct tm* tmb, const charT* fmt);
14
15#include <cassert>
16#include <ctime>
17#include <iomanip>
18#include <istream>
19#include <streambuf>
20
21#include "test_macros.h"
22#include "platform_support.h" // locale name macros
23
24template <class CharT>
25struct testbuf
26 : public std::basic_streambuf<CharT>
27{
28 typedef std::basic_string<CharT> string_type;
29 typedef std::basic_streambuf<CharT> base;
30private:
31 string_type str_;
32public:
33
34 testbuf() {}
35 testbuf(const string_type& str)
36 : str_(str)
37 {
38 base::setg(const_cast<CharT*>(str_.data()),
39 const_cast<CharT*>(str_.data()),
40 const_cast<CharT*>(str_.data()) + str_.size());
41 }
42};
43
44int main(int, char**)
45{
46 {
47 testbuf<char> sb(" Sat Dec 31 23:55:59 2061");
48 std::istream is(&sb);
49 is.imbue(std::locale(LOCALE_en_US_UTF_8));
50 std::tm t = {};
51 is >> std::get_time(tmb: &t, fmt: "%a %b %d %H:%M:%S %Y");
52 assert(t.tm_sec == 59);
53 assert(t.tm_min == 55);
54 assert(t.tm_hour == 23);
55 assert(t.tm_mday == 31);
56 assert(t.tm_mon == 11);
57 assert(t.tm_year == 161);
58 assert(t.tm_wday == 6);
59 assert(is.eof());
60 assert(!is.fail());
61 }
62#ifndef TEST_HAS_NO_WIDE_CHARACTERS
63 {
64 testbuf<wchar_t> sb(L" Sat Dec 31 23:55:59 2061");
65 std::wistream is(&sb);
66 is.imbue(std::locale(LOCALE_en_US_UTF_8));
67 std::tm t = {};
68 is >> std::get_time(tmb: &t, fmt: L"%a %b %d %H:%M:%S %Y");
69 assert(t.tm_sec == 59);
70 assert(t.tm_min == 55);
71 assert(t.tm_hour == 23);
72 assert(t.tm_mday == 31);
73 assert(t.tm_mon == 11);
74 assert(t.tm_year == 161);
75 assert(t.tm_wday == 6);
76 assert(is.eof());
77 assert(!is.fail());
78 }
79#endif
80
81 return 0;
82}
83

source code of libcxx/test/std/input.output/iostream.format/ext.manip/get_time.pass.cpp