aboutsummaryrefslogtreecommitdiffstats
path: root/util/human/io.lua
diff options
context:
space:
mode:
Diffstat (limited to 'util/human/io.lua')
-rw-r--r--util/human/io.lua12
1 files changed, 12 insertions, 0 deletions
diff --git a/util/human/io.lua b/util/human/io.lua
index 8a903d38..c2ed4904 100644
--- a/util/human/io.lua
+++ b/util/human/io.lua
@@ -197,6 +197,17 @@ local function new_table(col_specs, max_width)
end, max_width;
end
+local day = 86400;
+local multipliers = {
+ d = day, w = day * 7, m = 31 * day, mo = 31 * day, y = 365.2425 * day;
+ s = 1, mi = 60, h = 3600
+};
+local function parse_duration(duration_string)
+ local n, m = duration_string:lower():match("(%d+)%s*([dwmy]?.?)");
+ if not n then return nil; end
+ return tonumber(n) * ( multipliers[m] or 1 );
+end
+
return {
getchar = getchar;
getline = getline;
@@ -210,4 +221,5 @@ return {
term_width = term_width;
ellipsis = ellipsis;
table = new_table;
+ parse_duration = parse_duration;
};