summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-04-15 23:19:18 +0200
committerGitHub <noreply@github.com>2017-04-15 23:19:18 +0200
commit34d32ce55ae4f3f29d7b645075dc8efacb2c96d2 (patch)
tree6e21a37780352412b853fd242b6177eff2afd0fd /src/util
parent0f955bf7fa7a1376acdbc06a617c0f15f9fad467 (diff)
downloadminetest-34d32ce55ae4f3f29d7b645075dc8efacb2c96d2.tar.gz
minetest-34d32ce55ae4f3f29d7b645075dc8efacb2c96d2.tar.bz2
minetest-34d32ce55ae4f3f29d7b645075dc8efacb2c96d2.zip
Implement delayed server shutdown with cancelation (#4664)
Diffstat (limited to 'src/util')
-rw-r--r--src/util/string.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/util/string.h b/src/util/string.h
index 572c37150..c155d2f4a 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -614,4 +614,28 @@ inline const char *bool_to_cstr(bool val)
return val ? "true" : "false";
}
+inline const std::string duration_to_string(int sec)
+{
+ int min = floor(sec / 60);
+ sec %= 60;
+ int hour = floor(min / 60);
+ min %= 60;
+
+ std::stringstream ss;
+ if (hour > 0) {
+ ss << hour << "h ";
+ }
+
+ if (min > 0) {
+ ss << min << "m ";
+ }
+
+ if (sec > 0) {
+ ss << sec << "s ";
+ }
+
+ return ss.str();
+}
+
+
#endif