Skip to content

Commit

Permalink
Made use of std::put_time over util::strftime
Browse files Browse the repository at this point in the history
  • Loading branch information
Vultraz committed Dec 12, 2016
1 parent cf412fc commit 3f91b45
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/addon/manager_ui.cpp
Expand Up @@ -1017,7 +1017,7 @@ bool addons_manager_ui(CVideo& v, const std::string& remote_address)

addons_list addons;

if(gui2::new_widgets) {
if(true) {

This comment has been minimized.

Copy link
@CelticMinstrel

CelticMinstrel Dec 12, 2016

Member

Wait what?

config cfg;
client.request_addons_list(cfg);
if(!cfg) {
Expand Down
17 changes: 8 additions & 9 deletions src/gui/dialogs/addon/description.cpp
Expand Up @@ -27,27 +27,26 @@
#include "gui/widgets/window.hpp"
#include "language.hpp"
#include "preferences.hpp"
#include "strftime.hpp"

#include "utils/functional.hpp"

#include <iomanip>
#include <stdexcept>

namespace
{
std::string format_addon_time(time_t time)
static std::string format_addon_time(time_t time)
{
if(time) {
char buf[1024] = { 0 };
struct std::tm* const t = std::localtime(&time);
std::ostringstream ss;

const char* format = preferences::use_twelve_hour_clock_format()
? "%Y-%m-%d %I:%M %p"
: "%Y-%m-%d %H:%M";
? "%Y-%m-%d %I:%M %p"
: "%Y-%m-%d %H:%M";

if(util::strftime(buf, sizeof(buf), format, t)) {
return buf;
}
ss << std::put_time(std::localtime(&time), format);

return ss.str();
}

return font::unicode_em_dash;
Expand Down
16 changes: 8 additions & 8 deletions src/gui/dialogs/addon/manager.cpp
Expand Up @@ -47,12 +47,13 @@
#include "serialization/string_utils.hpp"
#include "formula/string_utils.hpp"
#include "preferences.hpp"
#include "strftime.hpp"
#include "utils/general.hpp"

#include "config.hpp"

#include "utils/functional.hpp"

#include <iomanip>
#include <sstream>
#include <stdexcept>

Expand Down Expand Up @@ -457,16 +458,15 @@ void addon_manager::copy_url_callback(text_box& url_box)
static std::string format_addon_time(time_t time)
{
if(time) {
char buf[1024] = { 0 };
struct std::tm* const t = std::localtime(&time);
std::ostringstream ss;

const char* format = preferences::use_twelve_hour_clock_format()
? "%Y-%m-%d %I:%M %p"
: "%Y-%m-%d %H:%M";
? "%Y-%m-%d %I:%M %p"
: "%Y-%m-%d %H:%M";

if(util::strftime(buf, sizeof(buf), format, t)) {
return buf;
}
ss << std::put_time(std::localtime(&time), format);

return ss.str();
}

return font::unicode_em_dash;
Expand Down
17 changes: 9 additions & 8 deletions src/reports.cpp
Expand Up @@ -29,7 +29,6 @@
#include "mouse_events.hpp"
#include "reports.hpp"
#include "color.hpp"
#include "strftime.hpp"
#include "team.hpp"
#include "tod_manager.hpp"
#include "units/unit.hpp"
Expand All @@ -38,6 +37,7 @@

#include <cassert>
#include <ctime>
#include <iomanip>
#include <boost/dynamic_bitset.hpp>

static void add_text(config &report, const std::string &text,
Expand Down Expand Up @@ -1524,15 +1524,16 @@ REPORT_GENERATOR(edit_left_button_function)

REPORT_GENERATOR(report_clock, /*rc*/)
{
std::ostringstream ss;

const char* format = preferences::use_twelve_hour_clock_format()
? "%I:%M %p"
: "%H:%M";

time_t t = std::time(nullptr);
struct tm *lt = std::localtime(&t);
if (!lt) return config();
char temp[15];
size_t s = util::strftime(temp, 15,
(preferences::use_twelve_hour_clock_format() ? _("%I:%M %p") : _("%H:%M")),
lt);
return s ? text_report(temp) : config();
ss << std::put_time(std::localtime(&t), format);

return text_report(ss.str());
}

REPORT_GENERATOR(report_countdown, rc)
Expand Down

0 comments on commit 3f91b45

Please sign in to comment.