Skip to content

Commit

Permalink
Merge pull request #65 from monaqa/fix-osdate_in_windows
Browse files Browse the repository at this point in the history
fix: `%-m` and others does not work on Windows
  • Loading branch information
monaqa committed Mar 26, 2023
2 parents 5020da9 + ce8e858 commit 94c4649
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion lua/dial/augend/date.lua
Expand Up @@ -143,21 +143,37 @@ local date_elements = {
date.year = 2000 + tonumber(text)
return date
end,
format = function(time)
local year = os.date("*t", time).year --[[ @as integer ]]
return tostring(year % 100)
end,
},
["-m"] = {
kind = "month",
regex = [[\d\{1,2\}]],
update_date = simple_updater "month",
format = function(time)
local month = os.date("*t", time).month --[[ @as integer ]]
return tostring(month)
end,
},
["-d"] = {
kind = "day",
regex = [[\d\{1,2\}]],
update_date = simple_updater "day",
format = function(time)
local day = os.date("*t", time).day --[[ @as integer ]]
return tostring(day)
end,
},
["-H"] = {
kind = "hour",
regex = [[\d\{1,2\}]],
update_date = simple_updater "hour",
format = function(time)
local hour = os.date("*t", time).hour --[[ @as integer ]]
return tostring(hour)
end,
},
["-I"] = {
kind = "hour",
Expand All @@ -173,16 +189,29 @@ local date_elements = {
end
return date
end,
format = function(time)
local hour = os.date("*t", time).hour --[[ @as integer ]]
-- 0 -> 12, 1 -> 1, 2 -> 2, ..., 12 -> 12, ..., 23 -> 11
return tostring((hour + 11) % 12 + 1)
end,
},
["-M"] = {
kind = "min",
regex = [[\d\{1,2\}]],
update_date = simple_updater "min",
format = function(time)
local min = os.date("*t", time).min --[[ @as integer ]]
return tostring(min)
end,
},
["-S"] = {
kind = "sec",
regex = [[\d\{1,2\}]],
update_date = simple_updater "sec",
format = function(time)
local sec = os.date("*t", time).sec --[[ @as integer ]]
return tostring(sec)
end,
},

-- names
Expand Down Expand Up @@ -728,7 +757,7 @@ M.alias["%H:%M:%S"] = M.new {
M.alias["%H:%M"] = M.new {
pattern = "%H:%M",
default_kind = "sec",
default_kind = "min",
only_valid = true,
}
Expand Down

0 comments on commit 94c4649

Please sign in to comment.