Skip to content

Commit

Permalink
feat(metagen): more precise timestamp with HH:MM:SS and timezone (#1052)
Browse files Browse the repository at this point in the history
resolves #1042
  • Loading branch information
champignoom committed Sep 6, 2023
1 parent 4f0888b commit a8f7a9e
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions lua/neorg/modules/core/esupports/metagen/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ local config, modules, utils = neorg.config, neorg.modules, neorg.utils
local module = modules.create("core.esupports.metagen")
local function get_timezone_offset()
-- http://lua-users.org/wiki/TimeZon
-- return the timezone offset in seconds, as it was on the time given by ts
-- Eric Feliksik
local utcdate = os.date("!*t", 0)
local localdate = os.date("*t", 0)
localdate.isdst = false -- this is the trick
return os.difftime(os.time(localdate), os.time(utcdate))
end
local function get_timestamp()
-- generate a ISO-8601 timestamp
-- example: 2023-09-05T09:09:11-0500
local tz_offset = get_timezone_offset()
local h, m = math.modf(tz_offset / 3600)
return os.date("%Y-%m-%dT%H:%M:%S") .. string.format("%+.4d", h * 100 + m * 60)
end
module.setup = function()
return { requires = { "core.autocommands", "core.keybinds", "core.integrations.treesitter" } }
end
Expand Down Expand Up @@ -63,18 +81,14 @@ module.config.public = {
-- The created field is populated with the current date as returned by `os.date`.
{
"created",
function()
return os.date("%Y-%m-%d")
end,
get_timestamp,
},
-- When creating fresh, new metadata, the updated field is populated the same way
-- as the `created` date.
{
"updated",
function()
return os.date("%Y-%m-%d")
end,
get_timestamp,
},
-- The version field determines which Norg version was used when
Expand Down

0 comments on commit a8f7a9e

Please sign in to comment.