X-Git-Url: https://git.r.bdr.sh/rbdr/nota.nvim/blobdiff_plain/503d09fc95a47c13141d097cf80dd243d1dce342..9e9e89d8556ecafa6b11ab21aa9ffab550f7f3ad:/lua/util.lua diff --git a/lua/util.lua b/lua/util.lua index 2636e7c..de53228 100644 --- a/lua/util.lua +++ b/lua/util.lua @@ -29,11 +29,15 @@ end ------------------------------------------------------------------------------- -- 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 = {...} @@ -45,4 +49,28 @@ function Util.directory_name(file_path) 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