From c7d7a01fa8e05ba073d220bfff305f140681f5bf Mon Sep 17 00:00:00 2001 From: MrBounty Date: Sun, 20 Oct 2024 10:15:25 +0200 Subject: [PATCH] Log now print always the same length When printing 12:03 it was 12;3 before, now it's fix and use the DateTime.format function --- src/fileEngine.zig | 6 +++++- src/types/date.zig | 4 +--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/fileEngine.zig b/src/fileEngine.zig index ab7bd1c..39495c1 100644 --- a/src/fileEngine.zig +++ b/src/fileEngine.zig @@ -135,7 +135,11 @@ pub const FileEngine = struct { const now = DateTime.now(); // TODO: Use a format to add the 0 to be 00:00 and not 0:0 - writer.print("Time: {d}/{d}/{d}-{d}:{d}:{d}.{d} - ", .{ now.years, now.months, now.days, now.hours, now.minutes, now.seconds, now.ms }) catch return; + var date_format_buffer = std.ArrayList(u8).init(self.allocator); + defer date_format_buffer.deinit(); + + now.format("YYYY/MM/DD-HH:mm:ss.SSSS", date_format_buffer.writer()) catch return; + writer.print("Time: {s} - ", .{date_format_buffer.items}) catch return; switch (level) { .Debug => writer.print("Debug - ", .{}) catch return, .Info => writer.print("Info - ", .{}) catch return, diff --git a/src/types/date.zig b/src/types/date.zig index 072c544..a1a3561 100644 --- a/src/types/date.zig +++ b/src/types/date.zig @@ -237,9 +237,7 @@ pub const DateTime = struct { } /// fmt is based on https://momentjs.com/docs/#/displaying/format/ - pub fn format(self: Self, comptime fmt: string, options: std.fmt.FormatOptions, writer: anytype) !void { - _ = options; - + pub fn format(self: Self, comptime fmt: string, writer: anytype) !void { if (fmt.len == 0) @compileError("DateTime: format string can't be empty"); @setEvalBranchQuota(100000);