From 88e8b25fa1bc15fb7baae46454cbdf072552eabc Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Tue, 6 Dec 2022 09:28:38 -0500 Subject: [PATCH] [Bug Fix] Data Bucket Permanent Duration String (#2624) # Notes - "F" or "f" weren't handled in this method, so they weren't working properly. - Most people don't provide this parameter when setting a permanent data bucket, so wasn't noticed in testing. --- common/strings.cpp | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/common/strings.cpp b/common/strings.cpp index 48481a50b..fd31e3272 100644 --- a/common/strings.cpp +++ b/common/strings.cpp @@ -685,32 +685,37 @@ uint32 Strings::TimeToSeconds(std::string time_string) return 0; } - uint32 duration = 0; + time_string = Strings::ToLower(time_string); - std::transform(time_string.begin(), time_string.end(), time_string.begin(), ::tolower); + if (time_string == "f") { + return 0; + } std::string time_unit = time_string; - time_unit.erase(remove_if(time_unit.begin(), time_unit.end(), [](char c) { return !isdigit(c); }), time_unit.end()); + + time_unit.erase( + remove_if( + time_unit.begin(), + time_unit.end(), + [](char c) { + return !isdigit(c); + } + ), + time_unit.end() + ); auto unit = std::stoul(time_unit); + uint32 duration = 0; - if (time_string.find('s') != std::string::npos) { + if (Strings::Contains(time_string, "s")) { duration = unit; - } - - if (time_string.find('m') != std::string::npos) { + } else if (Strings::Contains(time_string, "m")) { duration = unit * 60; - } - - if (time_string.find('h') != std::string::npos) { + } else if (Strings::Contains(time_string, "h")) { duration = unit * 3600; - } - - if (time_string.find('d') != std::string::npos) { + } else if (Strings::Contains(time_string, "d")) { duration = unit * 86400; - } - - if (time_string.find('y') != std::string::npos) { + } else if (Strings::Contains(time_string, "y")) { duration = unit * 31556926; }