Used std::put time everywhere

The utils::put_time wrapper was only for GCC 4.x.

(cherry-picked from commit 80c2d1a405)
This commit is contained in:
Charles Dang 2018-03-18 23:29:07 +11:00
parent 24cc0b01d4
commit 4f1c4dcafd
8 changed files with 5 additions and 71 deletions

View file

@ -447,12 +447,7 @@ std::string strftime(const std::string& format, const std::tm* time)
std::basic_ostringstream<char> dummy;
std::lock_guard<std::mutex> lock(get_mutex());
dummy.imbue(get_manager().get_locale());
// See utils/io.hpp for explanation of this check
#if HAVE_PUT_TIME
dummy << std::put_time(time, format.c_str());
#else
dummy << bl::as::ftime(format) << mktime(const_cast<std::tm*>(time));
#endif
return dummy.str();
}

View file

@ -45,7 +45,6 @@
// Some C++11 features are not available on all supported platforms
#if defined(_MSC_VER)
#define HAVE_PUT_TIME 1
// MSVC supports these starting in MSVC 2015
#if _MSC_VER >= 1900
#define HAVE_REF_QUALIFIERS 1
@ -71,13 +70,6 @@
#if defined(__clang__)
#include <ciso646> // To ensure standard library version macros are defined
// If it's libc++, no problem. Otherwise, attempt to detect libstdc++ version (needs GCC 5.1 or higher)
// by testing for the existence of a header added in that version.
#if defined(_LIBCPP_VERSION) || __has_include(<experimental/any>) || __has_include(<any>)
#define HAVE_PUT_TIME 1
#else
#define HAVE_PUT_TIME 0
#endif
// Clang has convenient feature detection macros \o/
#define HAVE_REF_QUALIFIERS __has_feature(cxx_reference_qualified_functions)
@ -91,8 +83,6 @@
#endif
#if defined(__GNUC__) && !defined(__clang__)
// GCC 5 required for this
#define HAVE_PUT_TIME (__GNUC__ >= 5)
// GCC supports these from 4.8 up
#define NORETURN [[noreturn]]
#define HAVE_REF_QUALIFIERS 1

View file

@ -60,7 +60,6 @@
#include <iomanip>
#include <sstream>
#include <stdexcept>
#include "utils/io.hpp"
namespace gui2
{
@ -842,7 +841,7 @@ static std::string format_addon_time(time_t time)
? "%Y-%m-%d %I:%M %p"
: "%Y-%m-%d %H:%M";
ss << utils::put_time(std::localtime(&time), format);
ss << std::put_time(std::localtime(&time), format);
return ss.str();
}

View file

@ -29,7 +29,6 @@
#include "gui/widgets/scrollbar_container.hpp"
#include "gui/widgets/window.hpp"
#include "serialization/string_utils.hpp"
#include "utils/io.hpp"
#include <fstream>
#include <iostream>
@ -86,7 +85,7 @@ std::string get_base_filename()
std::ostringstream ss;
time_t t = time(nullptr);
ss << utils::put_time(std::localtime(&t), "%Y%m%d_%H%M%S");
ss << std::put_time(std::localtime(&t), "%Y%m%d_%H%M%S");
static unsigned counter = 0;
++counter;

View file

@ -28,7 +28,6 @@
#include <ctime>
#include "global.hpp"
#include "utils/io.hpp"
namespace {
@ -176,7 +175,7 @@ bool broke_strict() {
std::string get_timestamp(const time_t& t, const std::string& format) {
std::ostringstream ss;
ss << utils::put_time(std::localtime(&t), format.c_str());
ss << std::put_time(std::localtime(&t), format.c_str());
return ss.str();
}

View file

@ -28,8 +28,6 @@
#include <boost/algorithm/string/predicate.hpp>
#include "utils/io.hpp"
#ifndef UNICODE
#define UNICODE
#endif
@ -112,7 +110,7 @@ std::string unique_log_filename()
o << log_file_prefix;
const time_t cur = time(nullptr);
o << utils::put_time(std::localtime(&cur), "%Y%m%d-%H%M%S-");
o << std::put_time(std::localtime(&cur), "%Y%m%d-%H%M%S-");
o << GetCurrentProcessId() << log_file_suffix;

View file

@ -35,8 +35,6 @@
#include <iomanip>
#include <boost/dynamic_bitset.hpp>
#include "utils/io.hpp"
static void add_text(config &report, const std::string &text,
const std::string &tooltip, const std::string &help = "")
{
@ -1537,7 +1535,7 @@ REPORT_GENERATOR(report_clock, /*rc*/)
: "%H:%M";
time_t t = std::time(nullptr);
ss << utils::put_time(std::localtime(&t), format);
ss << std::put_time(std::localtime(&t), format);
return text_report(ss.str(), _("Clock"));
}

View file

@ -1,44 +0,0 @@
/*
Copyright (C) 2003 - 2018 the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#include "global.hpp"
// The version of libstdc++ shipped with GCC 4.x does not have put_time in the <iomanip> header
// Thus if GCC is the compiler being used, we can simply check the compiler version.
// However, if clang is being used, this won't work.
// Instead, we check for the presence of the <experimental/any> header.
// This was introduced in GCC 5.1, so it's not a perfect check, but it appears to be the best available.
// (Boost also uses the same check internally.)
#if !HAVE_PUT_TIME
#include <ctime>
namespace utils {
inline std::string put_time(struct tm* time, const char* fmt) {
char buf[256];
if(strftime(buf, 256, fmt, time)) {
return buf;
}
return "<badtime>";
}
}
#else
#include <iomanip>
namespace utils {
using std::put_time;
}
#endif