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 {...@@ -13,7 +13,6 @@ pub const DateTime = struct {
13 years: u16,13 years: u16,
14 timezone: TimeZone,14 timezone: TimeZone,
15 weekday: WeekDay,15 weekday: WeekDay,
16 era: Era,
1716
18 const Self = @This();17 const Self = @This();
1918
...@@ -50,7 +49,6 @@ pub const DateTime = struct {...@@ -50,7 +49,6 @@ pub const DateTime = struct {
50 .years = 1970,49 .years = 1970,
51 .timezone = .UTC,50 .timezone = .UTC,
52 .weekday = .Thu,51 .weekday = .Thu,
53 .era = .AD,
54 };52 };
5553
56 pub fn eql(self: Self, other: Self) bool {54 pub fn eql(self: Self, other: Self) bool {
...@@ -271,7 +269,7 @@ pub const DateTime = struct {...@@ -271,7 +269,7 @@ pub const DateTime = struct {
271 .YYY => try writer.print("{}", .{self.years}),269 .YYY => try writer.print("{}", .{self.years}),
272 .YYYY => try writer.print("{:0>4}", .{self.years}),270 .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())),
275 .NN => try writer.writeAll("Anno Domini"),273 .NN => try writer.writeAll("Anno Domini"),
276274
277 .A => try printLongName(writer, self.hours / 12, &[_]string{ "AM", "PM" }),275 .A => try printLongName(writer, self.hours / 12, &[_]string{ "AM", "PM" }),
...@@ -388,6 +386,11 @@ pub const DateTime = struct {...@@ -388,6 +386,11 @@ pub const DateTime = struct {
388 .ms = self.toUnixMilli() - other_in_the_past.toUnixMilli(),386 .ms = self.toUnixMilli() - other_in_the_past.toUnixMilli(),
389 };387 };
390 }388 }
389
390 pub fn era(self: Self) Era {
391 if (self.years >= 0) return .AD;
392 @compileError("TODO");
393 }
391};394};
392395
393pub const format = struct {396pub const format = struct {