Miscellaneous fixes

This commit is contained in:
Nathan Fisher 2024-01-29 23:05:44 -05:00
parent 9547839328
commit 95c8113136

View File

@ -114,7 +114,7 @@ pub const DateTime = struct {
seconds -= 60; seconds -= 60;
minutes -= 1; minutes -= 1;
} }
const second = @intCast(u6, seconds + 60); const second = @as(u6, @intCast(seconds + 60));
return Self{ return Self{
.year = year, .year = year,
.month = month.?, .month = month.?,
@ -145,15 +145,15 @@ pub const DateTime = struct {
return Self{ return Self{
.year = year, .year = year,
.month = month, .month = month,
.day = @intCast(u8, day), .day = @as(u8, @intCast(day)),
.hour = @intCast(u5, hour), .hour = @as(u5, @intCast(hour)),
.minute = @intCast(u6, minute), .minute = @as(u6, @intCast(minute)),
.second = @intCast(u6, seconds), .second = @as(u6, @intCast(seconds)),
.tz = .utc, .tz = .utc,
}; };
} else { } else {
return Self{ return Self{
.year = Year.new(0), .year = Year.new(1970),
.month = .january, .month = .january,
.day = 1, .day = 1,
.hour = 0, .hour = 0,
@ -171,7 +171,7 @@ pub const DateTime = struct {
pub fn weekday(self: Self) WeekDay { pub fn weekday(self: Self) WeekDay {
const ts = self.toTimestamp(); const ts = self.toTimestamp();
const days = @divTrunc(ts, SECONDS_PER_DAY); const days = @divTrunc(ts, SECONDS_PER_DAY);
return @intToEnum(WeekDay, @rem(days, 7)); return @as(WeekDay, @enumFromInt(@rem(days, 7)));
} }
pub fn compare(self: Self, other: Self) Comparison { pub fn compare(self: Self, other: Self) Comparison {
@ -190,7 +190,7 @@ pub const DateTime = struct {
_ = options; _ = options;
try writer.print("{s}-{d:0>2}-{d:0>2}", .{ try writer.print("{s}-{d:0>2}-{d:0>2}", .{
self.year, @enumToInt(self.month), self.day, self.year, @intFromEnum(self.month), self.day,
}); });
if (self.hour) |h| { if (self.hour) |h| {
try writer.print("T{d:0>2}", .{h}); try writer.print("T{d:0>2}", .{h});
@ -209,7 +209,7 @@ pub const DateTime = struct {
writer: anytype, writer: anytype,
) !void { ) !void {
try writer.print("{s}{d:0>2}{d:0>2}", .{ try writer.print("{s}{d:0>2}{d:0>2}", .{
self.year, @enumToInt(self.month), self.day, self.year, @intFromEnum(self.month), self.day,
}); });
if (self.hour) |h| { if (self.hour) |h| {
try writer.print("T{d:0>2}", .{h}); try writer.print("T{d:0>2}", .{h});