resolve some errors with date calculations when creating a note from the

calendar.
This commit is contained in:
Liquidmantis
2021-12-12 15:53:07 -07:00
parent 4f21732ae8
commit 8d920f9650

View File

@@ -174,13 +174,13 @@ local function daysuffix(day)
end end
local daymap = { local daymap = {
"Sunday",
"Monday", "Monday",
"Tuesday", "Tuesday",
"Wednesday", "Wednesday",
"Thursday", "Thursday",
"Friday", "Friday",
"Saturday", "Saturday",
"Sunday",
} }
local monthmap = { local monthmap = {
"January", "January",
@@ -212,8 +212,17 @@ local function calculate_dates(cinfo)
local df = dateformats local df = dateformats
local opts = {} local opts = {}
opts.date = os.date(df.date)
local wday = dinfo.wday - 1 -- compensate for 1-indexed os.date output -- this is to compensate for the calendar showing M-Su, but os.date Su is
-- always wday = 1
local wday = dinfo.wday - 1
if wday == 0 then
wday = 7
end
opts.year = dinfo.year
opts.month = dinfo.month
opts.day = dinfo.day
opts.hdate = daymap[wday] opts.hdate = daymap[wday]
.. ", " .. ", "
.. monthmap[dinfo.month] .. monthmap[dinfo.month]
@@ -222,10 +231,8 @@ local function calculate_dates(cinfo)
.. daysuffix(dinfo.day) .. daysuffix(dinfo.day)
.. ", " .. ", "
.. dinfo.year .. dinfo.year
opts.month = dinfo.month
opts.year = dinfo.year
opts.day = dinfo.day
opts.date = os.date(df.date, time)
opts.prevday = os.date(df.date, time - oneday) opts.prevday = os.date(df.date, time - oneday)
opts.nextday = os.date(df.date, time + oneday) opts.nextday = os.date(df.date, time + oneday)
opts.week = os.date(df.week, time) opts.week = os.date(df.week, time)