feat(Core/Common): add new helpers for time utility (#10207)

This commit is contained in:
Kargatum
2022-01-19 12:01:59 +07:00
committed by GitHub
parent b5ab409614
commit 259b9133f6
60 changed files with 732 additions and 341 deletions

View File

@@ -474,9 +474,7 @@ public:
Field* fields2 = banInfo->Fetch();
do
{
time_t timeBan = time_t(fields2[0].GetUInt32());
tm tmBan;
localtime_r(&timeBan, &tmBan);
tm tmBan = Acore::Time::TimeBreakdown(fields2[0].GetUInt32());
if (fields2[0].GetUInt32() == fields2[1].GetUInt32())
{
@@ -486,9 +484,7 @@ public:
}
else
{
time_t timeUnban = time_t(fields2[1].GetUInt32());
tm tmUnban;
localtime_r(&timeUnban, &tmUnban);
tm tmUnban = Acore::Time::TimeBreakdown(fields2[1].GetUInt32());
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
accountName.c_str(), tmBan.tm_year % 100, tmBan.tm_mon + 1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
tmUnban.tm_year % 100, tmUnban.tm_mon + 1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
@@ -562,9 +558,7 @@ public:
Field* banFields = banInfo->Fetch();
do
{
time_t timeBan = time_t(banFields[0].GetUInt32());
tm tmBan;
localtime_r(&timeBan, &tmBan);
tm tmBan = Acore::Time::TimeBreakdown(banFields[0].GetUInt32());
if (banFields[0].GetUInt32() == banFields[1].GetUInt32())
{
@@ -574,9 +568,7 @@ public:
}
else
{
time_t timeUnban = time_t(banFields[1].GetUInt32());
tm tmUnban;
localtime_r(&timeUnban, &tmUnban);
tm tmUnban = Acore::Time::TimeBreakdown(banFields[1].GetUInt32());
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
char_name.c_str(), tmBan.tm_year % 100, tmBan.tm_mon + 1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
tmUnban.tm_year % 100, tmUnban.tm_mon + 1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,
@@ -640,9 +632,7 @@ public:
{
handler->SendSysMessage("-------------------------------------------------------------------------------");
Field* fields = result->Fetch();
time_t timeBan = time_t(fields[1].GetUInt32());
tm tmBan;
localtime_r(&timeBan, &tmBan);
tm tmBan = Acore::Time::TimeBreakdown(fields[1].GetUInt32());
if (fields[1].GetUInt32() == fields[2].GetUInt32())
{
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
@@ -651,9 +641,7 @@ public:
}
else
{
time_t timeUnban = time_t(fields[2].GetUInt32());
tm tmUnban;
localtime_r(&timeUnban, &tmUnban);
tm tmUnban = Acore::Time::TimeBreakdown(fields[2].GetUInt32());
handler->PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
fields[0].GetCString(), tmBan.tm_year % 100, tmBan.tm_mon + 1, tmBan.tm_mday, tmBan.tm_hour, tmBan.tm_min,
tmUnban.tm_year % 100, tmUnban.tm_mon + 1, tmUnban.tm_mday, tmUnban.tm_hour, tmUnban.tm_min,

View File

@@ -33,6 +33,7 @@ EndScriptData */
#include "PlayerDump.h"
#include "ReputationMgr.h"
#include "ScriptMgr.h"
#include "Timer.h"
#include "World.h"
#include "WorldSession.h"
@@ -182,7 +183,7 @@ public:
for (DeletedInfoList::const_iterator itr = foundList.begin(); itr != foundList.end(); ++itr)
{
std::string dateStr = TimeToTimestampStr(itr->deleteDate);
std::string dateStr = Acore::Time::TimeToTimestampStr(Seconds(itr->deleteDate));
if (!handler->GetSession())
handler->PSendSysMessage(LANG_CHARACTER_DELETED_LIST_LINE_CONSOLE,

View File

@@ -27,6 +27,7 @@
#include "Language.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "Timer.h"
using namespace Acore::ChatCommands;
@@ -111,12 +112,12 @@ public:
bool active = activeEvents.find(eventId) != activeEvents.end();
char const* activeStr = active ? handler->GetAcoreString(LANG_ACTIVE) : "";
std::string startTimeStr = TimeToTimestampStr(eventData.start);
std::string endTimeStr = TimeToTimestampStr(eventData.end);
std::string startTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.start));
std::string endTimeStr = Acore::Time::TimeToTimestampStr(Seconds(eventData.end));
uint32 delay = sGameEventMgr->NextCheck(eventId);
time_t nextTime = time(nullptr) + delay;
std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? TimeToTimestampStr(time(nullptr) + delay) : "-";
std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? Acore::Time::TimeToTimestampStr(Seconds(time(nullptr) + delay)) : "-";
std::string occurenceStr = secsToTimeString(eventData.occurence * MINUTE, true);
std::string lengthStr = secsToTimeString(eventData.length * MINUTE, true);

View File

@@ -15,11 +15,11 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ScriptMgr.h"
#include "Chat.h"
#include "Language.h"
#include "Log.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "WorldSession.h"
using namespace Acore::ChatCommands;

View File

@@ -15,12 +15,12 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ScriptMgr.h"
#include "Chat.h"
#include "DatabaseEnv.h"
#include "GroupMgr.h"
#include "Language.h"
#include "Player.h"
#include "ScriptMgr.h"
using namespace Acore::ChatCommands;

View File

@@ -231,14 +231,7 @@ public:
handler->PSendSysMessage(LANG_GUILD_INFO_GUILD_MASTER, guildMasterName.c_str(), guild->GetLeaderGUID().GetCounter()); // Guild Master
}
// Format creation date
char createdDateStr[20];
time_t createdDate = guild->GetCreatedDate();
tm localTm;
localtime_r(&createdDate, &localTm);
strftime(createdDateStr, 20, "%Y-%m-%d %H:%M:%S", &localTm);
handler->PSendSysMessage(LANG_GUILD_INFO_CREATION_DATE, createdDateStr); // Creation Date
handler->PSendSysMessage(LANG_GUILD_INFO_CREATION_DATE, Acore::Time::TimeToHumanReadable(Seconds(guild->GetCreatedDate())).c_str()); // Creation Date
handler->PSendSysMessage(LANG_GUILD_INFO_MEMBER_COUNT, guild->GetMemberCount()); // Number of Members
handler->PSendSysMessage(LANG_GUILD_INFO_BANK_GOLD, guild->GetTotalBankMoney() / 100 / 100); // Bank Gold (in gold coins)
handler->PSendSysMessage(LANG_GUILD_INFO_MOTD, guild->GetMOTD().c_str()); // Message of the day

View File

@@ -15,10 +15,10 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ScriptMgr.h"
#include "Chat.h"
#include "Language.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "WorldSession.h"
constexpr std::array<const char*, MAX_ITEM_SUBCLASS_CONTAINER> bagSpecsToString =

View File

@@ -23,12 +23,12 @@ Category: commandscripts
EndScriptData */
#include "Chat.h"
#include "DatabaseEnv.h"
#include "DBCStores.h"
#include "DatabaseEnv.h"
#include "Language.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "Language.h"
using namespace Acore::ChatCommands;

View File

@@ -39,8 +39,8 @@
#include "ScriptMgr.h"
#include "SpellAuras.h"
#include "TargetedMovementGenerator.h"
#include "WeatherMgr.h"
#include "Tokenize.h"
#include "WeatherMgr.h"
// TODO: this import is not necessary for compilation and marked as unused by the IDE
// however, for some reasons removing it would cause a damn linking issue
@@ -2556,17 +2556,7 @@ public:
do
{
Field* fields = result->Fetch();
// we have to manually set the string for mutedate
time_t sqlTime = fields[0].GetUInt32();
tm timeInfo;
char buffer[80];
// set it to string
localtime_r(&sqlTime, &timeInfo);
strftime(buffer, sizeof(buffer), "%Y-%m-%d %I:%M%p", &timeInfo);
handler->PSendSysMessage(LANG_COMMAND_MUTEHISTORY_OUTPUT, buffer, fields[1].GetUInt32(), fields[2].GetCString(), fields[3].GetCString());
handler->PSendSysMessage(LANG_COMMAND_MUTEHISTORY_OUTPUT, Acore::Time::TimeToHumanReadable(Seconds(fields[0].GetUInt32())).c_str(), fields[1].GetUInt32(), fields[2].GetCString(), fields[3].GetCString());
} while (result->NextRow());
return true;

View File

@@ -15,15 +15,15 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ScriptMgr.h"
#include "Chat.h"
#include "Language.h"
#include "Log.h"
#include "ObjectMgr.h"
#include "Pet.h"
#include "Player.h"
#include "SpellMgr.h"
#include "ScriptMgr.h"
#include "SpellInfo.h"
#include "SpellMgr.h"
#include "WorldSession.h"
using namespace Acore::ChatCommands;

View File

@@ -15,7 +15,6 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ScriptMgr.h"
#include "Chat.h"
#include "DatabaseEnv.h"
#include "Item.h"
@@ -24,6 +23,7 @@
#include "ObjectMgr.h"
#include "Pet.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "Tokenize.h"
using namespace Acore::ChatCommands;

View File

@@ -23,8 +23,8 @@ Category: commandscripts
EndScriptData */
#include "Chat.h"
#include "DatabaseEnv.h"
#include "DBCStores.h"
#include "DatabaseEnv.h"
#include "Group.h"
#include "Language.h"
#include "MapMgr.h"