diff --git a/lua/gitlab/actions/summary.lua b/lua/gitlab/actions/summary.lua index dfde1d73..6d034be1 100644 --- a/lua/gitlab/actions/summary.lua +++ b/lua/gitlab/actions/summary.lua @@ -93,7 +93,7 @@ M.build_info_lines = function() local options = { author = { title = "Author", content = "@" .. info.author.username .. " (" .. info.author.name .. ")" }, created_at = { title = "Created", content = u.format_to_local(info.created_at, vim.fn.strftime("%z")) }, - updated_at = { title = "Updated", content = u.format_to_local(info.updated_at, vim.fn.strftime("%z")) }, + updated_at = { title = "Updated", content = u.time_since(info.updated_at) }, detailed_merge_status = { title = "Status", content = info.detailed_merge_status }, draft = { title = "Draft", content = (info.draft and "Yes" or "No") }, conflicts = { title = "Merge Conflicts", content = (info.has_conflicts and "Yes" or "No") }, diff --git a/lua/gitlab/utils/init.lua b/lua/gitlab/utils/init.lua index 2729da1a..1404fbf2 100644 --- a/lua/gitlab/utils/init.lua +++ b/lua/gitlab/utils/init.lua @@ -254,6 +254,20 @@ M.format_to_local = function(date_string, offset) local tzOffsetSign, tzOffsetHour, tzOffsetMin year, month, day, hour, min, sec, _, tzOffsetSign, tzOffsetHour, tzOffsetMin = date_string:match("(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+).(%d+)([%+%-])(%d%d):(%d%d)") + + -- ISO 8601 format with just "Z" (aka no time offset) + -- 2021-01-01T00:00:00Z + if year == nil then + year, month, day, hour, min, sec = date_string:match("(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)Z") + tzOffsetSign = "-" + tzOffsetHour = "00" + tzOffsetMin = "00" + end + + if year == nil then + return "Date Unparseable" + end + tzOffset = tzOffsetSign .. tzOffsetHour .. tzOffsetMin end diff --git a/tests/spec/util_spec.lua b/tests/spec/util_spec.lua index 629a2b84..0a569a79 100644 --- a/tests/spec/util_spec.lua +++ b/tests/spec/util_spec.lua @@ -77,6 +77,13 @@ describe("utils/init.lua", function() local want = "November 19, 2011" assert.are.same(want, got) end) + + it("Parses TZ w/out offset (relative)", function() + local stamp = "2023-11-14T18:44:02Z" + local got = u.time_since(stamp, current_date) + local want = "5 days ago" + assert.are.same(want, got) + end) end) describe("remove_first_value", function() @@ -209,6 +216,7 @@ describe("utils/init.lua", function() { "2016-11-21T20:25:09.482-05:00", "-0500", "11/21/2016 at 20:25" }, { "2016-11-22T1:25:09.482-00:00", "-0000", "11/22/2016 at 01:25" }, { "2017-3-22T20:25:09.482+07:00", "+0700", "03/22/2017 at 20:25" }, + { "2016-11-22T1:25:09Z", "-0000", "11/22/2016 at 01:25" }, } for _, val in ipairs(tests) do local got = u.format_to_local(val[1], val[2])