From 00026d62950a929f1c92a0adeff62028bc0035d7 Mon Sep 17 00:00:00 2001 From: skovati Date: Tue, 3 Jan 2023 13:46:27 +0000 Subject: [PATCH] Add new precise time (hour:min:sec) templating options (#197) * add new more precise time templating options * add docs for new time template options --- README.md | 2 ++ doc/telekasten.txt | 2 ++ lua/telekasten.lua | 35 +++++++++-------------------------- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 0d487a2..4320f3e 100644 --- a/README.md +++ b/README.md @@ -845,6 +845,8 @@ Currently, the following substitutions will be made during new note creation: | `{{shorttitle}}` | the short title of the note | dir/subdir/My Note -> My Note | | `{{uuid}}` | UUID for the note | 202201271129 | | `{{date}}` | date in iso format | 2021-11-21 | +| `{{time24}}` | time with 24 hour clock | 19:12:23 | +| `{{time12}}` | time with 12 hour clock | 07:12:23 PM | | `{{prevday}}` | previous day's date in iso format | 2021-11-20 | | `{{nextday}}` | next day's date in iso format | 2021-11-22 | | `{{hdate}}` | date in long format | Sunday, November 21st, 2021 | diff --git a/doc/telekasten.txt b/doc/telekasten.txt index 35e7be7..5bb1993 100644 --- a/doc/telekasten.txt +++ b/doc/telekasten.txt @@ -900,6 +900,8 @@ The following substitutions will be made during new note creation: | `{{shorttitle}} | the short title of the note | dir/dir/My Note -> My Note | | `{{uuid}}` | UUID of the note | 202201271129 | | `{{date}}` | date in iso format | 2021-11-21 | +| `{{time24}}` | time with 24 hour clock | 19:12:23 | +| `{{time12}}` | time with 12 hour clock | 07:12:23 PM | | `{{prevday}}` | previous day, iso | 2021-11-20 | | `{{nextday}}` | next day, iso | 2021-11-22 | | `{{hdate}}` | date in long format | Sunday, November 21st, 2021 | diff --git a/lua/telekasten.lua b/lua/telekasten.lua index 31c8937..18aa08c 100644 --- a/lua/telekasten.lua +++ b/lua/telekasten.lua @@ -552,6 +552,8 @@ local dateformats = { date = "%Y-%m-%d", week = "%V", isoweek = "%Y-W%V", + time24 = "%H:%M:%S", + time12 = "%I:%M:%S %p", } local function calculate_dates(date) @@ -591,6 +593,8 @@ local function calculate_dates(date) .. ":" .. zonemin + dates.time24 = os.date(df.time24, time) + dates.time12 = os.date(df.time12, time) dates.date = os.date(df.date, time) dates.prevday = os.date(df.date, time - oneday) dates.nextday = os.date(df.date, time + oneday) @@ -644,33 +648,12 @@ local function linesubst(line, title, dates, uuid) shorttitle = title end - local substs = { - hdate = dates.hdate, - week = dates.week, - date = dates.date, - isoweek = dates.isoweek, - year = dates.year, - rfc3339 = dates.rfc3339, + local substs = vim.tbl_extend("error", dates, { + shorttitle, + uuid, + title, + }) - prevday = dates.prevday, - nextday = dates.nextday, - prevweek = dates.prevweek, - nextweek = dates.nextweek, - isoprevweek = dates.isoprevweek, - isonextweek = dates.isonextweek, - - sunday = dates.sunday, - monday = dates.monday, - tuesday = dates.tuesday, - wednesday = dates.wednesday, - thursday = dates.thursday, - friday = dates.friday, - saturday = dates.saturday, - - title = title, - shorttitle = shorttitle, - uuid = uuid, - } for k, v in pairs(substs) do line = line:gsub("{{" .. k .. "}}", v) end