authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-07-14 17:45:26 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-07-14 17:45:26 -07:00
log926bbdc1f0f7109b0ef1425eb24b727a5e0b21c9
tree0e5ea914d742417a5efc567e2f90fe4d74709c67
parentddd3541ba3514a86c3bd9425a86882f16c2a266d
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

DateTime: fix toISOString


2 files changed, 9 insertions(+), 6 deletions(-)

time.zig+8-6
......@@ -2,6 +2,7 @@ const std = @import("std");
22const builtin = @import("builtin");
33const string = []const u8;
44const extras = @import("extras");
5const nio = @import("nio");
56const sys_linux = @import("sys-linux");
67const time = @This();
78
......@@ -56,13 +57,14 @@ pub const DateTime = struct {
5657 .z_offset = 0,
5758 };
5859
59 pub fn toISOString(self: DateTime) [20]u8 {
60 // "2021-10-21T23:20:30Z"
61 var result: [20]u8 = @splat(0);
62 var fbs = std.io.fixedBufferStream(&result);
63 self.format("YYYY-MM-DD HH:mm:ss", .{}, fbs.writer()) catch unreachable;
60 pub fn toISOString(self: DateTime) [25]u8 {
61 // "2021-10-21T23:20:30+00:00"
62 var result: [25]u8 = @splat(0);
63 var fbs: nio.FixedBufferStream([]u8) = .init(&result);
64 self.formatFmt("YYYY-MM-DD HH:mm:ss", &fbs) catch unreachable;
65 fbs = .init(result[19..]);
66 self.formatFmt("Z", &fbs) catch unreachable;
6467 result[10] = 'T';
65 result[19] = 'Z';
6668 return result;
6769 }
6870
zig.mod+1
......@@ -7,5 +7,6 @@ dependencies:
77 - src: git https://github.com/nektro/zig-extras
88 - src: git https://github.com/nektro/zig-sys-linux
99 - src: git https://github.com/nektro/zig-sys-darwin
10 - src: git https://github.com/nektro/zig-nio
1011root_dependencies:
1112 - src: git https://github.com/nektro/zig-expect