Changeset - r27418:86b1bec802f9
[Not reviewed]
master
1 6 0
Rubidium - 13 months ago 2023-05-20 14:14:12
rubidium@openttd.org
Codechange: use fmt::format and time conversions over "custom" implementation
7 files changed with 13 insertions and 105 deletions:
0 comments (0 inline, 0 general)
src/CMakeLists.txt
Show inline comments
 
@@ -512,7 +512,6 @@ add_files(
 
    viewport_type.h
 
    void_cmd.cpp
 
    void_map.h
 
    walltime_func.h
 
    water.h
 
    water_cmd.cpp
 
    water_cmd.h
src/console_cmds.cpp
Show inline comments
 
@@ -42,7 +42,7 @@
 
#include "rail.h"
 
#include "game/game.hpp"
 
#include "table/strings.h"
 
#include "walltime_func.h"
 
#include "3rdparty/fmt/chrono.h"
 
#include "company_cmd.h"
 
#include "misc_cmd.h"
 

	
 
@@ -1460,9 +1460,7 @@ DEF_CONSOLE_CMD(ConGetSysDate)
 
		return true;
 
	}
 

	
 
	char buffer[lengthof("2000-01-02 03:04:05")];
 
	LocalTime::Format(buffer, lastof(buffer), "%Y-%m-%d %H:%M:%S");
 
	IConsolePrint(CC_DEFAULT, "System Date: {}", buffer);
 
	IConsolePrint(CC_DEFAULT, "System Date: {:%Y-%m-%d %H:%M:%S}", fmt::localtime(time(nullptr)));
 
	return true;
 
}
 

	
src/crashlog.cpp
Show inline comments
 
@@ -33,7 +33,7 @@
 
#include "game/game_info.hpp"
 
#include "company_base.h"
 
#include "company_func.h"
 
#include "walltime_func.h"
 
#include "3rdparty/fmt/chrono.h"
 

	
 
#ifdef WITH_ALLEGRO
 
#	include <allegro.h>
 
@@ -342,8 +342,7 @@ int CrashLog::CreateFileName(char *filen
 
	static std::string crashname;
 

	
 
	if (crashname.empty()) {
 
		UTCTime::Format(filename, filename_last, "crash%Y%m%d%H%M%S");
 
		crashname = filename;
 
		crashname = fmt::format("crash{:%Y%m%d%H%M%S}", fmt::gmtime(time(nullptr)));
 
	}
 
	return seprintf(filename, filename_last, "%s%s%s", with_dir ? _personal_dir.c_str() : "", crashname.c_str(), ext);
 
}
 
@@ -357,7 +356,8 @@ int CrashLog::CreateFileName(char *filen
 
char *CrashLog::FillCrashLog(char *buffer, const char *last) const
 
{
 
	buffer += seprintf(buffer, last, "*** OpenTTD Crash Report ***\n\n");
 
	buffer += UTCTime::Format(buffer, last, "Crash at: %Y-%m-%d %H:%M:%S (UTC)\n");
 
	std::string temp = fmt::format("Crash at: {:%Y-%m-%d %H:%M:%S} (UTC)\n", fmt::gmtime(time(nullptr)));
 
	buffer = strecpy(buffer, temp.c_str(), last);
 

	
 
	TimerGameCalendar::YearMonthDay ymd;
 
	TimerGameCalendar::ConvertDateToYMD(TimerGameCalendar::date, &ymd);
src/debug.cpp
Show inline comments
 
@@ -19,7 +19,7 @@
 
#include "os/windows/win32.h"
 
#endif
 

	
 
#include "walltime_func.h"
 
#include "3rdparty/fmt/chrono.h"
 

	
 
#include "network/network_admin.h"
 
SOCKET _debug_socket = INVALID_SOCKET;
 
@@ -245,13 +245,13 @@ const char *GetDebugString()
 
 */
 
const char *GetLogPrefix()
 
{
 
	static char _log_prefix[24];
 
	static std::string _log_prefix;
 
	if (_settings_client.gui.show_date_in_logs) {
 
		LocalTime::Format(_log_prefix, lastof(_log_prefix), "[%Y-%m-%d %H:%M:%S] ");
 
		_log_prefix = fmt::format("[{:%Y-%m-%d %H:%M:%S}] ", fmt::localtime(time(nullptr)));
 
	} else {
 
		*_log_prefix = '\0';
 
		_log_prefix.clear();
 
	}
 
	return _log_prefix;
 
	return _log_prefix.c_str();
 
}
 

	
 
/**
src/newgrf_profiling.cpp
Show inline comments
 
@@ -12,7 +12,7 @@
 
#include "string_func.h"
 
#include "console_func.h"
 
#include "spritecache.h"
 
#include "walltime_func.h"
 
#include "3rdparty/fmt/chrono.h"
 
#include "timer/timer.h"
 
#include "timer/timer_game_tick.h"
 

	
 
@@ -131,13 +131,7 @@ void NewGRFProfiler::Abort()
 
 */
 
std::string NewGRFProfiler::GetOutputFilename() const
 
{
 
	char timestamp[16] = {};
 
	LocalTime::Format(timestamp, lastof(timestamp), "%Y%m%d-%H%M");
 

	
 
	char filepath[MAX_PATH] = {};
 
	seprintf(filepath, lastof(filepath), "%sgrfprofile-%s-%08X.csv", FiosGetScreenshotDir(), timestamp, BSWAP32(this->grffile->grfid));
 

	
 
	return std::string(filepath);
 
	return fmt::format("{}grfprofile-{%Y%m%d-%H%M}-{:08X}.csv", FiosGetScreenshotDir(), fmt::localtime(time(nullptr)), BSWAP32(this->grffile->grfid));
 
}
 

	
 
/* static */ uint32 NewGRFProfiler::FinishAll()
src/stdafx.h
Show inline comments
 
@@ -93,7 +93,6 @@
 
	/* Warn about functions using 'printf' format syntax. First argument determines which parameter
 
	 * is the format string, second argument is start of values passed to printf. */
 
#	define WARN_FORMAT(string, args) __attribute__ ((format (printf, string, args)))
 
#	define WARN_TIME_FORMAT(string) __attribute__ ((format (strftime, string, 0)))
 
#	if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)
 
#		define FINAL final
 
#	else
 
@@ -129,7 +128,6 @@
 
#	define NORETURN
 
#	define CDECL
 
#	define WARN_FORMAT(string, args)
 
#	define WARN_TIME_FORMAT(string)
 
#	define FINAL
 
#	define FALLTHROUGH
 
#	include <malloc.h>
 
@@ -172,7 +170,6 @@
 

	
 
#	define CDECL _cdecl
 
#	define WARN_FORMAT(string, args)
 
#	define WARN_TIME_FORMAT(string)
 
#	define FINAL final
 

	
 
	/* fallthrough attribute, VS 2017 */
src/walltime_func.h
Show inline comments
 
deleted file
0 comments (0 inline, 0 general)