30 lines
600 B
Zig
30 lines
600 B
Zig
const std = @import("std");
|
|
const Self = @This();
|
|
|
|
const time = @cImport({
|
|
@cInclude("time.h");
|
|
});
|
|
|
|
buf: []u8,
|
|
|
|
pub fn init(self: *Self, alloc: std.mem.Allocator) !void {
|
|
self.buf = try alloc.alloc(u8, 64);
|
|
errdefer alloc.free(self.buf);
|
|
}
|
|
|
|
pub fn update(self: *Self) ![]const u8 {
|
|
const tt: time.time_t = time.time(null);
|
|
const tp = time.localtime(&tt);
|
|
const n = time.strftime(
|
|
self.buf.ptr,
|
|
self.buf.len,
|
|
"%c",
|
|
tp,
|
|
);
|
|
return self.buf[0..n];
|
|
}
|
|
|
|
pub fn deinit(self: *Self, alloc: std.mem.Allocator) void {
|
|
alloc.free(self.buf);
|
|
}
|