From af0708dbda5b7e548180845b3a7d07195124bd41 Mon Sep 17 00:00:00 2001 From: Liquidmantis Date: Fri, 10 Dec 2021 21:18:37 -0700 Subject: [PATCH] add date offsets for note templates --- README.md | 4 ++++ lua/telekasten.lua | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 55d3eb9..97853ac 100644 --- a/README.md +++ b/README.md @@ -617,8 +617,12 @@ Currently, the following substitutions will be made during new note creation: | --- | --- | --- | | `{{title}}` | the title of the note | My new note | | `{{date}}` | date in iso format | 2021-11-21 | +| `{{yesterday}}` | yesterday's date in iso format | 2021-11-20 | +| `{{tomorrow}}` | tomorrow's date in iso format | 2021-11-22 | | `{{hdate}}` | date in long format | Sunday, November 21st, 2021 | | `{{week}}` | week of the year | 46 | +| `{{lastweek}}` | prior week of the year | 45 | +| `{{nextweek}}` | next week of the year | 47 | | `{{year}}` | year | 2021 | As an example, this is my template for new notes: diff --git a/lua/telekasten.lua b/lua/telekasten.lua index 4267998..bf48d47 100644 --- a/lua/telekasten.lua +++ b/lua/telekasten.lua @@ -194,8 +194,14 @@ local monthmap = { local function calenderinfo_today() local dinfo = os.date("*t") + local oneday = 24 * 60 * 60 -- hours * days * seconds + local oneweek = 7 * oneday + local date_format = "%Y-%m-%d" + local week_format = "%V" local opts = {} - opts.date = os.date("%Y-%m-%d") + opts.date = os.date(date_format) + opts.yesterday = os.date(date_format, os.time() - oneday) + opts.tomorrow = os.date(date_format, os.time() + oneday) local wday = dinfo.wday - 1 if wday == 0 then wday = 7 @@ -211,7 +217,9 @@ local function calenderinfo_today() .. daysuffix(dinfo.day) .. ", " .. dinfo.year - opts.week = os.date("%V") + opts.week = os.date(week_format) + opts.lastweek = os.date(week_format, os.time() - oneweek) + opts.nextweek = os.date(week_format, os.time() + oneweek) opts.month = dinfo.month opts.year = dinfo.year opts.day = dinfo.day @@ -222,6 +230,10 @@ local function linesubst(line, title, calendar_info) local cinfo = calendar_info or calenderinfo_today() local substs = { date = cinfo.date, + yesterday = cinfo.yesterday, + tomorrow = cinfo.tomorrow, + lastweek = cinfo.lastweek, + nextweek = cinfo.nextweek, hdate = cinfo.hdate, week = cinfo.week, year = cinfo.year,