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:
parent
ae85f94ddb
commit
8138e5ccf2
1 changed files with 8 additions and 0 deletions
8
src/date_fmt.zig
Normal file
8
src/date_fmt.zig
Normal 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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue