authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-03-09 11:53:07 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2024-03-09 11:53:07 -08:00
log16dd344b261d3aef0a7adc90200d5d656bb03a16
tree576863e2dee3f86e678cb6700cd439534bc6d0e5
parenta01155929e335518792f38f404aa359bbf751de0

DateTime: make era calculated at runtime


1 files changed, 6 insertions(+), 3 deletions(-)

time.zig+6-3
......@@ -13,7 +13,6 @@ pub const DateTime = struct {
1313 years: u16,
1414 timezone: TimeZone,
1515 weekday: WeekDay,
16 era: Era,
1716
1817 const Self = @This();
1918
......@@ -50,7 +49,6 @@ pub const DateTime = struct {
5049 .years = 1970,
5150 .timezone = .UTC,
5251 .weekday = .Thu,
53 .era = .AD,
5452 };
5553
5654 pub fn eql(self: Self, other: Self) bool {
......@@ -271,7 +269,7 @@ pub const DateTime = struct {
271269 .YYY => try writer.print("{}", .{self.years}),
272270 .YYYY => try writer.print("{:0>4}", .{self.years}),
273271
274 .N => try writer.writeAll(@tagName(self.era)),
272 .N => try writer.writeAll(@tagName(self.era())),
275273 .NN => try writer.writeAll("Anno Domini"),
276274
277275 .A => try printLongName(writer, self.hours / 12, &[_]string{ "AM", "PM" }),
......@@ -388,6 +386,11 @@ pub const DateTime = struct {
388386 .ms = self.toUnixMilli() - other_in_the_past.toUnixMilli(),
389387 };
390388 }
389
390 pub fn era(self: Self) Era {
391 if (self.years >= 0) return .AD;
392 @compileError("TODO");
393 }
391394};
392395
393396pub const format = struct {