diff options
author | ForesterDev <11771800+ForesterDev@users.noreply.github.com> | 2020-02-23 00:31:37 +0400 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2021-12-22 01:25:24 +0100 |
commit | 69f768605082222a3ca573c623d3fc019106be3b (patch) | |
tree | 1045f82caa4c7eb3709033e57b250784e6d06956 /src/common/Utilities/Util.cpp | |
parent | 1d08423725141de712290b18739dcc9b3ea3a7c6 (diff) |
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 69231581e4f2d78384d3efe6f613be1b78e9d40f)
Diffstat (limited to 'src/common/Utilities/Util.cpp')
-rw-r--r-- | src/common/Utilities/Util.cpp | 73 |
1 files changed, 67 insertions, 6 deletions
diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index 57281bf4fd9..ceee94a8009 100644 --- a/src/common/Utilities/Util.cpp +++ b/src/common/Utilities/Util.cpp @@ -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(); |