From 20efc7adda3ea5295829075bb8b581fdcb1199d1 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Mon, 14 Feb 2022 16:35:03 +0000 Subject: Handle negative times in InspIRCd::Duration. --- src/helperfuncs.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/helperfuncs.cpp') 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"; -- cgit v1.3.1-10-gc9f91