From 7dc9f9ab2ad061b0b8be08e3a27cfe3056f1a76c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 7 Apr 2023 14:14:53 +0100 Subject: util.human.io: Add parse_duration() method to parse a duration string Similar logic occurs throughout various modules in the codebase. We might even want a module:get_option_duration()?? --- spec/util_human_io_spec.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'spec/util_human_io_spec.lua') diff --git a/spec/util_human_io_spec.lua b/spec/util_human_io_spec.lua index f1b28883..c143d028 100644 --- a/spec/util_human_io_spec.lua +++ b/spec/util_human_io_spec.lua @@ -42,6 +42,24 @@ describe("util.human.io", function () assert.equal("räksmörgås", human_io.ellipsis("räksmörgås", 10)); end); end); + + describe("parse_duration", function () + local function test(expected, duration) + assert.equal(expected, human_io.parse_duration(duration)); + end + it("works", function () + test(1, "1s"); + test(60, "1mi"); + test(60, "1min"); + test(60, "1 min"); + test(60, "1 minute"); + test(120, "2min"); + test(86400, "1d"); + test(2678400, "1m"); + test(2678400, "1month"); + test(2678400, "1 month"); + end); + end); end); -- cgit v1.2.3