Create dateFmt function

It's easier to keep the date as an epoch in PostgreSQL to do comparisons, but I always want to show it to the user as a formatted date
This commit is contained in:
mitteneer 2025-04-28 23:03:24 -04:00
parent ae85f94ddb
commit 8138e5ccf2

8
src/date_fmt.zig Normal file
View file

@ -0,0 +1,8 @@
const std = @import("std");
const zeit = @import("zeit");
pub fn dateFmt(allocator: std.mem.Allocator, epoch: i64) ![]const u8 {
var date = std.ArrayList(u8).init(allocator);
try (try zeit.instant(.{ .source = .{ .unix_timestamp = @divFloor(epoch, 1_000) } })).time().strftime(date.writer(), "%d %b %Y, %H:%M");
return date.items;
}