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");...@@ -2,6 +2,7 @@ const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const string = []const u8;3const string = []const u8;
4const extras = @import("extras");4const extras = @import("extras");
5const nio = @import("nio");
5const sys_linux = @import("sys-linux");6const sys_linux = @import("sys-linux");
6const time = @This();7const time = @This();
78
...@@ -56,13 +57,14 @@ pub const DateTime = struct {...@@ -56,13 +57,14 @@ pub const DateTime = struct {
56 .z_offset = 0,57 .z_offset = 0,
57 };58 };
5859
59 pub fn toISOString(self: DateTime) [20]u8 {60 pub fn toISOString(self: DateTime) [25]u8 {
60 // "2021-10-21T23:20:30Z"61 // "2021-10-21T23:20:30+00:00"
61 var result: [20]u8 = @splat(0);62 var result: [25]u8 = @splat(0);
62 var fbs = std.io.fixedBufferStream(&result);63 var fbs: nio.FixedBufferStream([]u8) = .init(&result);
63 self.format("YYYY-MM-DD HH:mm:ss", .{}, fbs.writer()) catch unreachable;64 self.formatFmt("YYYY-MM-DD HH:mm:ss", &fbs) catch unreachable;
65 fbs = .init(result[19..]);
66 self.formatFmt("Z", &fbs) catch unreachable;
64 result[10] = 'T';67 result[10] = 'T';
65 result[19] = 'Z';
66 return result;68 return result;
67 }69 }
6870
zig.mod+1
...@@ -7,5 +7,6 @@ dependencies:...@@ -7,5 +7,6 @@ dependencies:
7 - src: git https://github.com/nektro/zig-extras7 - src: git https://github.com/nektro/zig-extras
8 - src: git https://github.com/nektro/zig-sys-linux8 - src: git https://github.com/nektro/zig-sys-linux
9 - src: git https://github.com/nektro/zig-sys-darwin9 - src: git https://github.com/nektro/zig-sys-darwin
10 - src: git https://github.com/nektro/zig-nio
10root_dependencies:11root_dependencies:
11 - src: git https://github.com/nektro/zig-expect12 - src: git https://github.com/nektro/zig-expect