mirror of https://github.com/OpenTTD/OpenTTD.git
Add: 'getsysdate' console command (#7658)
Add `getsysdate` console command to display system's local time, which is might be useful to check current time in script logging.
This commit is contained in:
parent
afbf6a5918
commit
bcc73bd40d
|
@ -39,6 +39,7 @@
|
||||||
#include "engine_base.h"
|
#include "engine_base.h"
|
||||||
#include "game/game.hpp"
|
#include "game/game.hpp"
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "safeguards.h"
|
#include "safeguards.h"
|
||||||
|
|
||||||
|
@ -1302,13 +1303,27 @@ DEF_CONSOLE_CMD(ConGetSeed)
|
||||||
DEF_CONSOLE_CMD(ConGetDate)
|
DEF_CONSOLE_CMD(ConGetDate)
|
||||||
{
|
{
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
IConsoleHelp("Returns the current date (day-month-year) of the game. Usage: 'getdate'");
|
IConsoleHelp("Returns the current date (year-month-day) of the game. Usage: 'getdate'");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
YearMonthDay ymd;
|
YearMonthDay ymd;
|
||||||
ConvertDateToYMD(_date, &ymd);
|
ConvertDateToYMD(_date, &ymd);
|
||||||
IConsolePrintF(CC_DEFAULT, "Date: %d-%d-%d", ymd.day, ymd.month + 1, ymd.year);
|
IConsolePrintF(CC_DEFAULT, "Date: %04d-%02d-%02d", ymd.year, ymd.month + 1, ymd.day);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
DEF_CONSOLE_CMD(ConGetSysDate)
|
||||||
|
{
|
||||||
|
if (argc == 0) {
|
||||||
|
IConsoleHelp("Returns the current date (year-month-day) of your system. Usage: 'getsysdate'");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t t;
|
||||||
|
time(&t);
|
||||||
|
auto timeinfo = localtime(&t);
|
||||||
|
IConsolePrintF(CC_DEFAULT, "System Date: %04d-%02d-%02d %02d:%02d:%02d", timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1925,6 +1940,7 @@ void IConsoleStdLibRegister()
|
||||||
IConsoleCmdRegister("restart", ConRestart);
|
IConsoleCmdRegister("restart", ConRestart);
|
||||||
IConsoleCmdRegister("getseed", ConGetSeed);
|
IConsoleCmdRegister("getseed", ConGetSeed);
|
||||||
IConsoleCmdRegister("getdate", ConGetDate);
|
IConsoleCmdRegister("getdate", ConGetDate);
|
||||||
|
IConsoleCmdRegister("getsysdate", ConGetSysDate);
|
||||||
IConsoleCmdRegister("quit", ConExit);
|
IConsoleCmdRegister("quit", ConExit);
|
||||||
IConsoleCmdRegister("resetengines", ConResetEngines, ConHookNoNetwork);
|
IConsoleCmdRegister("resetengines", ConResetEngines, ConHookNoNetwork);
|
||||||
IConsoleCmdRegister("reset_enginepool", ConResetEnginePool, ConHookNoNetwork);
|
IConsoleCmdRegister("reset_enginepool", ConResetEnginePool, ConHookNoNetwork);
|
||||||
|
|
Loading…
Reference in New Issue