-------------------------------------------------------------------------------
-- Public Interface
-------------------------------------------------------------------------------
+-- File Utils
+
function Util.ensure_directory_exists(path)
local full_path = vim.fn.expand(path)
create_directory(path)
end
+-- Path Utils
+
function Util.join(...)
local separator = '/'
local paths = {...}
return file_path:match(pattern)
end
+-- Date Utils
+
+function Util.is_valid_date(date_string)
+ local pattern = '(%d+)-(%d+)-(%d+)'
+ local year, month, day = date_string:match(pattern)
+ if year and month and day then
+ return true
+ end
+ return false
+end
+
+function Util.is_before_today(date_string)
+ local pattern = '(%d+)-(%d+)-(%d+)'
+ local year, month, day = date_string:match(pattern)
+ if year and month and day then
+ local today = os.date('*t')
+ local today_date = os.time({year = today.year, month = today.month, day = today.day})
+ local date = os.time({year = tonumber(year), month = tonumber(month), day = tonumber(day)})
+ return date < today_date
+ else
+ return false
+ end
+end
+
return Util