diff --git a/src/util/DateTime.zig b/src/util/DateTime.zig index 199cdc3..2b096fa 100644 --- a/src/util/DateTime.zig +++ b/src/util/DateTime.zig @@ -117,14 +117,16 @@ pub fn toCharArrayZ(value: DateTime) [array_len + 1:0]u8 { return buf; } -pub fn format(value: DateTime, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void { - return std.fmt.format( - writer, - "{:0>4}-{:0>2}-{:0>2}T{:0>2}:{:0>2}:{:0>2}Z", - .{ value.year(), value.month().numeric(), value.day(), value.hour(), value.minute(), value.second() }, - ); +pub fn format(value: DateTime, comptime fmt: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void { + if (comptime std.ascii.eqlIgnoreCase(fmt, "rfc3339") or fmt.len == 0) { + return std.fmt.format( + writer, + "{:0>4}-{:0>2}-{:0>2}T{:0>2}:{:0>2}:{:0>2}Z", + .{ value.year(), value.month().numeric(), value.day(), value.hour(), value.minute(), value.second() }, + ); + } else @compileError("Unknown DateTime format " ++ fmt); } pub fn jsonStringify(value: DateTime, _: std.json.StringifyOptions, writer: anytype) !void { - try std.fmt.format(writer, "\"{}\"", .{value}); + try std.fmt.format(writer, "\"{rfc3339}\"", .{value}); }