From c5a061a49a22defcf34183df2477d89b9fed13cd Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Wed, 3 Apr 2024 14:36:16 -0400 Subject: [PATCH] nvim: implement the rest of date/time snippets --- src/.config/nvim/snippets/all.lua | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/.config/nvim/snippets/all.lua b/src/.config/nvim/snippets/all.lua index 4e42157..bb4fece 100644 --- a/src/.config/nvim/snippets/all.lua +++ b/src/.config/nvim/snippets/all.lua @@ -1,5 +1,28 @@ return { - s({ trig = "today", desc = "YYYY-MM-DD date of today" }, f(function () + -------------------------------- + -------------------------------- + -- date and timekeeping snippets + -------------------------------- + -------------------------------- + s({ trig = "today", desc = "YYYY-MM-DD date of today" }, f(function() return os.date("%Y-%m-%d") - end)) + end)), + s({ trig = "yesterday", desc = "YYYY-MM-DD date of yesterday" }, f(function() + local t = os.date("*t") + return os.date("%Y-%m-%d", os.time { year = t.year, month = t.month, day = t.day - 1 }) + end)), + + s({ trig = "timestamp", desc = "Unix day timestamp (locked to midnight)" }, f(function() + local t = os.date("*t") + return tostring(os.time { year = t.year, month = t.month, day = t.day, hour = 0 }) + end)), + s( + { + trig = "datestamp (%d-)-(%d-)-(%d-)", + regTrig = true, + desc = + "YYYY-MM-DD to Unix day timestamp (locked to midnight)" + }, f(function(_, snip) + return tostring(os.time { year = snip.captures[1], month = snip.captures[2], day = snip.captures[3], hour = 0 }) + end)), }