Skip to content

Commit a8f4da7

Browse files
committed
fix(commands): use strftime for session updated_at
1 parent d77dde2 commit a8f4da7

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

lua/peekstack/commands.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ local function session_updated_at_text(session)
3232
if type(updated_at) ~= "number" then
3333
return "unknown"
3434
end
35-
return os.date("%Y-%m-%d %H:%M:%S", updated_at)
35+
return vim.fn.strftime("%Y-%m-%d %H:%M:%S", updated_at)
3636
end
3737

3838
---@return string[]

tests/commands_spec.lua

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ describe("peekstack.commands", function()
55
local original_list_sessions = nil
66
local original_select = nil
77
local original_notify = nil
8+
local original_strftime = nil
89

910
before_each(function()
1011
config.setup({})
1112
commands._reset()
1213
original_list_sessions = persist.list_sessions
1314
original_select = vim.ui.select
1415
original_notify = vim.notify
16+
original_strftime = vim.fn.strftime
1517
end)
1618

1719
after_each(function()
@@ -25,6 +27,9 @@ describe("peekstack.commands", function()
2527
if original_notify then
2628
vim.notify = original_notify
2729
end
30+
if original_strftime then
31+
vim.fn.strftime = original_strftime
32+
end
2833
commands._reset()
2934
end)
3035

@@ -91,6 +96,45 @@ describe("peekstack.commands", function()
9196
assert.is_true(vim.list_contains(messages, "peekstack.persist is disabled"))
9297
end)
9398

99+
it("formats session updated_at with vim.fn.strftime", function()
100+
local prompts = {}
101+
local strftime_calls = {}
102+
103+
persist.list_sessions = function(opts)
104+
assert.is_truthy(opts)
105+
assert.is_truthy(opts.on_done)
106+
opts.on_done({
107+
alpha = {
108+
items = {},
109+
meta = { updated_at = 123 },
110+
},
111+
})
112+
return {}
113+
end
114+
115+
vim.fn.strftime = function(fmt, ts)
116+
table.insert(strftime_calls, { fmt = fmt, ts = ts })
117+
return "formatted-time"
118+
end
119+
120+
vim.ui.select = function(_items, opts, on_choice)
121+
table.insert(prompts, opts.prompt)
122+
if opts.prompt == "Select a session" then
123+
on_choice("alpha")
124+
return
125+
end
126+
on_choice("Info only")
127+
end
128+
129+
commands.setup()
130+
vim.api.nvim_cmd({ cmd = "PeekstackListSessions" }, {})
131+
132+
assert.equals(1, #strftime_calls)
133+
assert.equals("%Y-%m-%d %H:%M:%S", strftime_calls[1].fmt)
134+
assert.equals(123, strftime_calls[1].ts)
135+
assert.equals("alpha: 0 items (updated: formatted-time)", prompts[2])
136+
end)
137+
94138
it("includes extended providers in quick peek completion", function()
95139
commands.setup()
96140
local names = vim.fn.getcompletion("PeekstackQuickPeek ", "cmdline")

0 commit comments

Comments
 (0)