Add new precise time (hour:min:sec) templating options (#197)

* add new more precise time templating options

* add docs for new time template options
This commit is contained in:
skovati
2023-01-03 13:46:27 +00:00
committed by GitHub
parent 8d3f97b729
commit 00026d6295
3 changed files with 13 additions and 26 deletions

View File

@@ -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 | | `{{shorttitle}}` | the short title of the note | dir/subdir/My Note -> My Note |
| `{{uuid}}` | UUID for the note | 202201271129 | | `{{uuid}}` | UUID for the note | 202201271129 |
| `{{date}}` | date in iso format | 2021-11-21 | | `{{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 | | `{{prevday}}` | previous day's date in iso format | 2021-11-20 |
| `{{nextday}}` | next day's date in iso format | 2021-11-22 | | `{{nextday}}` | next day'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 |

View File

@@ -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 | | `{{shorttitle}} | the short title of the note | dir/dir/My Note -> My Note |
| `{{uuid}}` | UUID of the note | 202201271129 | | `{{uuid}}` | UUID of the note | 202201271129 |
| `{{date}}` | date in iso format | 2021-11-21 | | `{{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 | | `{{prevday}}` | previous day, iso | 2021-11-20 |
| `{{nextday}}` | next day, iso | 2021-11-22 | | `{{nextday}}` | next day, iso | 2021-11-22 |
| `{{hdate}}` | date in long format | Sunday, November 21st, 2021 | | `{{hdate}}` | date in long format | Sunday, November 21st, 2021 |

View File

@@ -552,6 +552,8 @@ local dateformats = {
date = "%Y-%m-%d", date = "%Y-%m-%d",
week = "%V", week = "%V",
isoweek = "%Y-W%V", isoweek = "%Y-W%V",
time24 = "%H:%M:%S",
time12 = "%I:%M:%S %p",
} }
local function calculate_dates(date) local function calculate_dates(date)
@@ -591,6 +593,8 @@ local function calculate_dates(date)
.. ":" .. ":"
.. zonemin .. zonemin
dates.time24 = os.date(df.time24, time)
dates.time12 = os.date(df.time12, time)
dates.date = os.date(df.date, time) dates.date = os.date(df.date, time)
dates.prevday = os.date(df.date, time - oneday) dates.prevday = os.date(df.date, time - oneday)
dates.nextday = 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 shorttitle = title
end end
local substs = { local substs = vim.tbl_extend("error", dates, {
hdate = dates.hdate, shorttitle,
week = dates.week, uuid,
date = dates.date, title,
isoweek = dates.isoweek, })
year = dates.year,
rfc3339 = dates.rfc3339,
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 for k, v in pairs(substs) do
line = line:gsub("{{" .. k .. "}}", v) line = line:gsub("{{" .. k .. "}}", v)
end end