Skip to content

Commit 0f3841f

Browse files
fix: parse dates without timezone offset (#404)
1 parent a63823c commit 0f3841f

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

lua/gitlab/actions/summary.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ M.build_info_lines = function()
9393
local options = {
9494
author = { title = "Author", content = "@" .. info.author.username .. " (" .. info.author.name .. ")" },
9595
created_at = { title = "Created", content = u.format_to_local(info.created_at, vim.fn.strftime("%z")) },
96-
updated_at = { title = "Updated", content = u.format_to_local(info.updated_at, vim.fn.strftime("%z")) },
96+
updated_at = { title = "Updated", content = u.time_since(info.updated_at) },
9797
detailed_merge_status = { title = "Status", content = info.detailed_merge_status },
9898
draft = { title = "Draft", content = (info.draft and "Yes" or "No") },
9999
conflicts = { title = "Merge Conflicts", content = (info.has_conflicts and "Yes" or "No") },

lua/gitlab/utils/init.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,20 @@ M.format_to_local = function(date_string, offset)
254254
local tzOffsetSign, tzOffsetHour, tzOffsetMin
255255
year, month, day, hour, min, sec, _, tzOffsetSign, tzOffsetHour, tzOffsetMin =
256256
date_string:match("(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+).(%d+)([%+%-])(%d%d):(%d%d)")
257+
258+
-- ISO 8601 format with just "Z" (aka no time offset)
259+
-- 2021-01-01T00:00:00Z
260+
if year == nil then
261+
year, month, day, hour, min, sec = date_string:match("(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)Z")
262+
tzOffsetSign = "-"
263+
tzOffsetHour = "00"
264+
tzOffsetMin = "00"
265+
end
266+
267+
if year == nil then
268+
return "Date Unparseable"
269+
end
270+
257271
tzOffset = tzOffsetSign .. tzOffsetHour .. tzOffsetMin
258272
end
259273

tests/spec/util_spec.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ describe("utils/init.lua", function()
7777
local want = "November 19, 2011"
7878
assert.are.same(want, got)
7979
end)
80+
81+
it("Parses TZ w/out offset (relative)", function()
82+
local stamp = "2023-11-14T18:44:02Z"
83+
local got = u.time_since(stamp, current_date)
84+
local want = "5 days ago"
85+
assert.are.same(want, got)
86+
end)
8087
end)
8188

8289
describe("remove_first_value", function()
@@ -209,6 +216,7 @@ describe("utils/init.lua", function()
209216
{ "2016-11-21T20:25:09.482-05:00", "-0500", "11/21/2016 at 20:25" },
210217
{ "2016-11-22T1:25:09.482-00:00", "-0000", "11/22/2016 at 01:25" },
211218
{ "2017-3-22T20:25:09.482+07:00", "+0700", "03/22/2017 at 20:25" },
219+
{ "2016-11-22T1:25:09Z", "-0000", "11/22/2016 at 01:25" },
212220
}
213221
for _, val in ipairs(tests) do
214222
local got = u.format_to_local(val[1], val[2])

0 commit comments

Comments
 (0)