authorgravatar for jamesrcalabro@gmail.comjcalabro <jamesrcalabro@gmail.com> 2023-07-31 21:14:54 -04:00
committergravatar for hello@nektro.netMeghan <hello@nektro.net> 2023-07-31 18:28:20 -07:00
log12fad367a5282827aad7e12f0e9cd36f672c4010
tree2597b18c8a641c1667040610267234553a9aad97
parentca9c0e6b644d74c1d549cc2c1ee22113aa021bd8

latest zig


1 files changed, 14 insertions(+), 14 deletions(-)

time.zig+14-14
......@@ -37,7 +37,7 @@ pub const DateTime = struct {
3737 }
3838
3939 pub fn now() Self {
40 return initUnixMs(@intCast(u64, std.time.milliTimestamp()));
40 return initUnixMs(@intCast(std.time.milliTimestamp()));
4141 }
4242
4343 pub const epoch_unix = Self{
......@@ -68,28 +68,28 @@ pub const DateTime = struct {
6868 pub fn addMs(self: Self, count: u64) Self {
6969 if (count == 0) return self;
7070 var result = self;
71 result.ms += @intCast(u16, count % 1000);
71 result.ms += @intCast(count % 1000);
7272 return result.addSecs(count / 1000);
7373 }
7474
7575 pub fn addSecs(self: Self, count: u64) Self {
7676 if (count == 0) return self;
7777 var result = self;
78 result.seconds += @intCast(u16, count % 60);
78 result.seconds += @intCast(count % 60);
7979 return result.addMins(count / 60);
8080 }
8181
8282 pub fn addMins(self: Self, count: u64) Self {
8383 if (count == 0) return self;
8484 var result = self;
85 result.minutes += @intCast(u16, count % 60);
85 result.minutes += @intCast(count % 60);
8686 return result.addHours(count / 60);
8787 }
8888
8989 pub fn addHours(self: Self, count: u64) Self {
9090 if (count == 0) return self;
9191 var result = self;
92 result.hours += @intCast(u16, count % 24);
92 result.hours += @intCast(count % 24);
9393 return result.addDays(count / 24);
9494 }
9595
......@@ -132,7 +132,7 @@ pub const DateTime = struct {
132132 result.days = 0;
133133 result.incrementWeekday(left);
134134 }
135 result.days += @intCast(u16, input);
135 result.days += @intCast(input);
136136 result.incrementWeekday(input);
137137
138138 if (result.months == 12) {
......@@ -187,7 +187,7 @@ pub const DateTime = struct {
187187 pub fn dayOfThisYear(self: Self) u16 {
188188 var ret: u16 = 0;
189189 for (0..self.months) |item| {
190 ret += self.daysInMonth(@intCast(u16, item));
190 ret += self.daysInMonth(@intCast(item));
191191 }
192192 ret += self.days;
193193 return ret;
......@@ -211,8 +211,8 @@ pub const DateTime = struct {
211211 fn daysSinceEpoch(self: Self) u64 {
212212 var res: u64 = 0;
213213 res += self.days;
214 for (0..self.years - epoch_unix.years) |i| res += time.daysInYear(@intCast(u16, i));
215 for (0..self.months) |i| res += self.daysInMonth(@intCast(u16, i));
214 for (0..self.years - epoch_unix.years) |i| res += time.daysInYear(@intCast(i));
215 for (0..self.months) |i| res += self.daysInMonth(@intCast(i));
216216 return res;
217217 }
218218
......@@ -254,13 +254,13 @@ pub const DateTime = struct {
254254 .DDDo => try printOrdinal(writer, self.dayOfThisYear() + 1),
255255 .DDDD => try writer.print("{:0>3}", .{self.dayOfThisYear() + 1}),
256256
257 .d => try writer.print("{}", .{@enumToInt(self.weekday)}),
258 .do => try printOrdinal(writer, @enumToInt(self.weekday)),
257 .d => try writer.print("{}", .{@intFromEnum(self.weekday)}),
258 .do => try printOrdinal(writer, @intFromEnum(self.weekday)),
259259 .dd => try writer.writeAll(@tagName(self.weekday)[0..2]),
260260 .ddd => try writer.writeAll(@tagName(self.weekday)),
261 .dddd => try printLongName(writer, @enumToInt(self.weekday), &[_]string{ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }),
262 .e => try writer.print("{}", .{@enumToInt(self.weekday)}),
263 .E => try writer.print("{}", .{@enumToInt(self.weekday) + 1}),
261 .dddd => try printLongName(writer, @intFromEnum(self.weekday), &[_]string{ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }),
262 .e => try writer.print("{}", .{@intFromEnum(self.weekday)}),
263 .E => try writer.print("{}", .{@intFromEnum(self.weekday) + 1}),
264264
265265 .w => try writer.print("{}", .{self.dayOfThisYear() / 7 + 1}),
266266 .wo => try printOrdinal(writer, self.dayOfThisYear() / 7 + 1),