From 16dd344b261d3aef0a7adc90200d5d656bb03a16 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sat, 9 Mar 2024 11:53:07 -0800 Subject: [PATCH] DateTime: make era calculated at runtime --- time.zig | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/time.zig b/time.zig index deecc947902167e45779bc15c8b70b4188918b67..2c07338a2ff6aabba9a87d5734f8c9f96bb7d07c 100644 --- a/time.zig +++ b/time.zig @@ -13,7 +13,6 @@ pub const DateTime = struct { years: u16, timezone: TimeZone, weekday: WeekDay, - era: Era, const Self = @This(); @@ -50,7 +49,6 @@ pub const DateTime = struct { .years = 1970, .timezone = .UTC, .weekday = .Thu, - .era = .AD, }; pub fn eql(self: Self, other: Self) bool { @@ -271,7 +269,7 @@ pub const DateTime = struct { .YYY => try writer.print("{}", .{self.years}), .YYYY => try writer.print("{:0>4}", .{self.years}), - .N => try writer.writeAll(@tagName(self.era)), + .N => try writer.writeAll(@tagName(self.era())), .NN => try writer.writeAll("Anno Domini"), .A => try printLongName(writer, self.hours / 12, &[_]string{ "AM", "PM" }), @@ -388,6 +386,11 @@ pub const DateTime = struct { .ms = self.toUnixMilli() - other_in_the_past.toUnixMilli(), }; } + + pub fn era(self: Self) Era { + if (self.years >= 0) return .AD; + @compileError("TODO"); + } }; pub const format = struct { -- 2.54.0