diff options
Diffstat (limited to 'src/cmd/date.zig')
-rw-r--r-- | src/cmd/date.zig | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/cmd/date.zig b/src/cmd/date.zig index a299667..3a7d72b 100644 --- a/src/cmd/date.zig +++ b/src/cmd/date.zig @@ -4,17 +4,15 @@ const print = std.debug.print; const types = @import("./lib/types.zig"); const CommandStatus = types.CommandStatus; -const OutputCapture = types.OutputCapture; -const InputSource = types.InputSource; +const CommandContext = types.CommandContext; fn isLeapYear(year: u32) bool { return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0); } pub const Date = struct { - pub fn eval(date: Date, allocator: Allocator, output_capture: ?*OutputCapture, input_source: ?*InputSource) !CommandStatus { + pub fn eval(date: Date, ctx: CommandContext) !CommandStatus { _ = date; - _ = input_source; const timestamp = std.time.timestamp(); const epoch_seconds = @as(u64, @intCast(timestamp)); @@ -56,9 +54,9 @@ pub const Date = struct { const day = remaining_days + 1; // Days are 1-indexed - const output = try std.fmt.allocPrint(allocator, "Current date is {d:0>2}/{d:0>2}/{d}\n", .{ month, day, year }); - defer allocator.free(output); - if (output_capture) |capture| { + const output = try std.fmt.allocPrint(ctx.allocator, "Current date is {d:0>2}/{d:0>2}/{d}\n", .{ month, day, year }); + defer ctx.allocator.free(output); + if (ctx.output_capture) |capture| { try capture.write(output); } else { print("{s}", .{output}); |