add date offsets for note templates

This commit is contained in:
Liquidmantis
2021-12-10 21:18:37 -07:00
parent 1c2bece95c
commit af0708dbda
2 changed files with 18 additions and 2 deletions

View File

@@ -617,8 +617,12 @@ Currently, the following substitutions will be made during new note creation:
| --- | --- | --- | | --- | --- | --- |
| `{{title}}` | the title of the note | My new note | | `{{title}}` | the title of the note | My new note |
| `{{date}}` | date in iso format | 2021-11-21 | | `{{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 | | `{{hdate}}` | date in long format | Sunday, November 21st, 2021 |
| `{{week}}` | week of the year | 46 | | `{{week}}` | week of the year | 46 |
| `{{lastweek}}` | prior week of the year | 45 |
| `{{nextweek}}` | next week of the year | 47 |
| `{{year}}` | year | 2021 | | `{{year}}` | year | 2021 |
As an example, this is my template for new notes: As an example, this is my template for new notes:

View File

@@ -194,8 +194,14 @@ local monthmap = {
local function calenderinfo_today() local function calenderinfo_today()
local dinfo = os.date("*t") 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 = {} 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 local wday = dinfo.wday - 1
if wday == 0 then if wday == 0 then
wday = 7 wday = 7
@@ -211,7 +217,9 @@ local function calenderinfo_today()
.. daysuffix(dinfo.day) .. daysuffix(dinfo.day)
.. ", " .. ", "
.. dinfo.year .. 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.month = dinfo.month
opts.year = dinfo.year opts.year = dinfo.year
opts.day = dinfo.day opts.day = dinfo.day
@@ -222,6 +230,10 @@ local function linesubst(line, title, calendar_info)
local cinfo = calendar_info or calenderinfo_today() local cinfo = calendar_info or calenderinfo_today()
local substs = { local substs = {
date = cinfo.date, date = cinfo.date,
yesterday = cinfo.yesterday,
tomorrow = cinfo.tomorrow,
lastweek = cinfo.lastweek,
nextweek = cinfo.nextweek,
hdate = cinfo.hdate, hdate = cinfo.hdate,
week = cinfo.week, week = cinfo.week,
year = cinfo.year, year = cinfo.year,