aboutsummaryrefslogtreecommitdiff
path: root/src/helperfuncs.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2022-02-14 16:35:03 +0000
committerGravatar Sadie Powell2022-02-14 20:28:08 +0000
commit20efc7adda3ea5295829075bb8b581fdcb1199d1 (patch)
tree0f0b30fc2ab89700c355a8a926cb2257e4bdf682 /src/helperfuncs.cpp
parentMake the accessor methods in ssl_cert const. (diff)
Handle negative times in InspIRCd::Duration.
Diffstat (limited to 'src/helperfuncs.cpp')
-rw-r--r--src/helperfuncs.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index 795f858fa..3aadb6080 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -426,25 +426,34 @@ std::string InspIRCd::DurationString(time_t duration)
if (duration == 0)
return "0s";
- time_t years = duration / 31449600;
- time_t weeks = (duration / 604800) % 52;
- time_t days = (duration / 86400) % 7;
- time_t hours = (duration / 3600) % 24;
- time_t minutes = (duration / 60) % 60;
- time_t seconds = duration % 60;
-
std::string ret;
+ if (duration < 0)
+ {
+ ret = "-";
+ duration = std::abs(duration);
+ }
+ time_t years = duration / 31449600;
if (years)
- ret = ConvToStr(years) + "y";
+ ret += ConvToStr(years) + "y";
+
+ time_t weeks = (duration / 604800) % 52;
if (weeks)
ret += ConvToStr(weeks) + "w";
+
+ time_t days = (duration / 86400) % 7;
if (days)
ret += ConvToStr(days) + "d";
+
+ time_t hours = (duration / 3600) % 24;
if (hours)
ret += ConvToStr(hours) + "h";
+
+ time_t minutes = (duration / 60) % 60;
if (minutes)
ret += ConvToStr(minutes) + "m";
+
+ time_t seconds = duration % 60;
if (seconds)
ret += ConvToStr(seconds) + "s";