mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-02-10 03:59:05 +01:00
Core/Server: correct timestamp format for shutdown/restart notification broadcasts (#24181)
* Core/SmartScripts: implement SMART_ACTION_OVERRIDE_LIGHT and SMART_ACTION_OVERRIDE_WEATHER
* Core/Server: correct timestamp format for shutdown/restart notification broadcasts
* remove unexpected changes
* move enum from Common to Util
* Use enum class instead of enum
* Fix width for seconds 0 to 9
(cherry picked from commit 69231581e4)
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include "StringFormat.h"
|
||||
#include <utf8.h>
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <cctype>
|
||||
@@ -108,7 +109,7 @@ time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime)
|
||||
return hourLocal;
|
||||
}
|
||||
|
||||
std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
|
||||
std::string secsToTimeString(uint64 timeInSecs, TimeFormat timeFormat, bool hoursOnly)
|
||||
{
|
||||
uint64 secs = timeInSecs % MINUTE;
|
||||
uint64 minutes = timeInSecs % HOUR / MINUTE;
|
||||
@@ -117,15 +118,75 @@ std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly)
|
||||
|
||||
std::ostringstream ss;
|
||||
if (days)
|
||||
ss << days << (shortText ? "d" : " Day(s) ");
|
||||
{
|
||||
ss << days;
|
||||
if (timeFormat == TimeFormat::Numeric)
|
||||
ss << ":";
|
||||
else if (timeFormat == TimeFormat::ShortText)
|
||||
ss << "d";
|
||||
else // if (timeFormat == TimeFormat::FullText)
|
||||
{
|
||||
if (days == 1)
|
||||
ss << " Day ";
|
||||
else
|
||||
ss << " Days ";
|
||||
}
|
||||
}
|
||||
if (hours || hoursOnly)
|
||||
ss << hours << (shortText ? "h" : " Hour(s) ");
|
||||
{
|
||||
ss << hours;
|
||||
if (timeFormat == TimeFormat::Numeric)
|
||||
ss << ":";
|
||||
else if (timeFormat == TimeFormat::ShortText)
|
||||
ss << "h";
|
||||
else // if (timeFormat == TimeFormat::FullText)
|
||||
{
|
||||
if (hours <= 1)
|
||||
ss << " Hour ";
|
||||
else
|
||||
ss << " Hours ";
|
||||
}
|
||||
}
|
||||
if (!hoursOnly)
|
||||
{
|
||||
if (minutes)
|
||||
ss << minutes << (shortText ? "m" : " Minute(s) ");
|
||||
if (secs || (!days && !hours && !minutes) )
|
||||
ss << secs << (shortText ? "s" : " Second(s).");
|
||||
{
|
||||
ss << minutes;
|
||||
if (timeFormat == TimeFormat::Numeric)
|
||||
ss << ":";
|
||||
else if (timeFormat == TimeFormat::ShortText)
|
||||
ss << "m";
|
||||
else // if (timeFormat == TimeFormat::FullText)
|
||||
{
|
||||
if (minutes == 1)
|
||||
ss << " Minute ";
|
||||
else
|
||||
ss << " Minutes ";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (timeFormat == TimeFormat::Numeric)
|
||||
ss << "0:";
|
||||
}
|
||||
if (secs || (!days && !hours && !minutes))
|
||||
{
|
||||
ss << std::setw(2) << std::setfill('0') << secs;
|
||||
if (timeFormat == TimeFormat::ShortText)
|
||||
ss << "s";
|
||||
else if (timeFormat == TimeFormat::FullText)
|
||||
{
|
||||
if (secs <= 1)
|
||||
ss << " Second.";
|
||||
else
|
||||
ss << " Seconds.";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (timeFormat == TimeFormat::Numeric)
|
||||
ss << "00";
|
||||
}
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
|
||||
Reference in New Issue
Block a user