feat: add commit age to git blame info

This commit is contained in:
CJ van den Berg 2026-02-13 12:22:52 +01:00
parent 030a2b86c1
commit fa71704a94
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9
4 changed files with 66 additions and 4 deletions

43
src/time_fmt.zig Normal file
View file

@ -0,0 +1,43 @@
pub fn age_short(timestamp: i64) struct {
timestamp: i64,
pub fn format(self: @This(), writer: anytype) std.Io.Writer.Error!void {
const age = std.time.timestamp() -| self.timestamp;
return if (age < 60)
writer.writeAll("now")
else if (age < 3600)
writer.print("{d}m", .{@divTrunc(age, 60)})
else if (age < 86400)
writer.print("{d}h", .{@divTrunc(age, 3600)})
else if (age < 2592000)
writer.print("{d}d", .{@divTrunc(age, 86400)})
else if (age < 31536000)
writer.print("{d}mo", .{@divTrunc(age, 2592000)})
else
writer.print("{d}y", .{@divTrunc(age, 31536000)});
}
} {
return .{ .timestamp = timestamp };
}
pub fn age_long(timestamp: i64) struct {
timestamp: i64,
pub fn format(self: @This(), writer: anytype) std.Io.Writer.Error!void {
const age = std.time.timestamp() -| self.timestamp;
return if (age < 60)
writer.writeAll("just now")
else if (age < 3600)
writer.print("{d} minutes ago", .{@divTrunc(age, 60)})
else if (age < 86400)
writer.print("{d} hours ago", .{@divTrunc(age, 3600)})
else if (age < 2592000)
writer.print("{d} days ago", .{@divTrunc(age, 86400)})
else if (age < 31536000)
writer.print("{d} months ago", .{@divTrunc(age, 2592000)})
else
writer.print("{d} years ago", .{@divTrunc(age, 31536000)});
}
} {
return .{ .timestamp = timestamp };
}
const std = @import("std");