Support format strings for datetimes
This commit is contained in:
parent
091146b617
commit
11bdaad6d7
1 changed files with 9 additions and 7 deletions
|
@ -117,14 +117,16 @@ pub fn toCharArrayZ(value: DateTime) [array_len + 1:0]u8 {
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn format(value: DateTime, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) !void {
|
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(
|
return std.fmt.format(
|
||||||
writer,
|
writer,
|
||||||
"{:0>4}-{:0>2}-{:0>2}T{:0>2}:{:0>2}:{:0>2}Z",
|
"{: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() },
|
.{ 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 {
|
pub fn jsonStringify(value: DateTime, _: std.json.StringifyOptions, writer: anytype) !void {
|
||||||
try std.fmt.format(writer, "\"{}\"", .{value});
|
try std.fmt.format(writer, "\"{rfc3339}\"", .{value});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue