From 944adb2be0fb50045b042474ec0bc7620b846a6c Mon Sep 17 00:00:00 2001 From: rootiest Date: Sat, 3 Aug 2024 04:47:30 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(wakatime):=20add=20get=5Ftotal?= =?UTF-8?q?=5Fminutes=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a function that returns an integer representing the total coding minutes for today --- lua/config/wakatime_cache.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lua/config/wakatime_cache.lua b/lua/config/wakatime_cache.lua index 4529dc1..b7615fc 100644 --- a/lua/config/wakatime_cache.lua +++ b/lua/config/wakatime_cache.lua @@ -44,4 +44,22 @@ function M.get_icon() end end +function M.get_total_minutes() + local wakatime_string = M.get_today() + if not wakatime_string or wakatime_string:match("Error:") then + return 0 -- Return 0 if there's an error in the wakatime string + end + + local hours, mins = wakatime_string:match("(%d+)%s*hrs?%s*(%d+)%s*mins?") + if not hours then + mins = wakatime_string:match("(%d+)%s*mins?") + hours = 0 + end + + hours = tonumber(hours) or 0 + mins = tonumber(mins) or 0 + + return (hours * 60) + mins +end + return M