Skip to content

Commit 4852518

Browse files
author
wooster0
committed
std: update to new std.time.epoch
1 parent 9982f9d commit 4852518

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

lib/compiler/aro/aro/Compilation.zig

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const std = @import("std");
22
const Allocator = mem.Allocator;
33
const assert = std.debug.assert;
4-
const EpochSeconds = std.time.epoch.EpochSeconds;
54
const mem = std.mem;
65
const Interner = @import("../backend.zig").Interner;
76
const Builtins = @import("Builtins.zig");
@@ -200,20 +199,20 @@ fn getTimestamp(comp: *Compilation) !u47 {
200199
}
201200

202201
fn generateDateAndTime(w: anytype, timestamp: u47) !void {
203-
const epoch_seconds = EpochSeconds{ .secs = timestamp };
204-
const epoch_day = epoch_seconds.getEpochDay();
205-
const day_seconds = epoch_seconds.getDaySeconds();
206-
const year_day = epoch_day.calculateYearDay();
207-
const month_day = year_day.calculateMonthDay();
202+
const seconds = std.time.epoch.Seconds{ .secs = timestamp };
203+
const days = seconds.getDays();
204+
const day_seconds = seconds.getSecondsIntoDay();
205+
const year_and_days = days.calculateYearAndDays();
206+
const month_and_day = year_and_days.calculateMonthAndDay();
208207

209208
const month_names = [_][]const u8{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
210209
std.debug.assert(std.time.epoch.Month.jan.numeric() == 1);
211210

212-
const month_name = month_names[month_day.month.numeric() - 1];
211+
const month_name = month_names[month_and_day.month.numeric() - 1];
213212
try w.print("#define __DATE__ \"{s} {d: >2} {d}\"\n", .{
214213
month_name,
215-
month_day.day_index + 1,
216-
year_day.year,
214+
month_and_day.day_index + 1,
215+
year_and_days.year,
217216
});
218217
try w.print("#define __TIME__ \"{d:0>2}:{d:0>2}:{d:0>2}\"\n", .{
219218
day_seconds.getHoursIntoDay(),
@@ -222,15 +221,15 @@ fn generateDateAndTime(w: anytype, timestamp: u47) !void {
222221
});
223222

224223
const day_names = [_][]const u8{ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
225-
const day_name = day_names[@intCast((epoch_day.day + 3) % 7)];
224+
const day_name = day_names[@intCast((days.days + 3) % 7)];
226225
try w.print("#define __TIMESTAMP__ \"{s} {s} {d: >2} {d:0>2}:{d:0>2}:{d:0>2} {d}\"\n", .{
227226
day_name,
228227
month_name,
229-
month_day.day_index + 1,
228+
month_and_day.day_index + 1,
230229
day_seconds.getHoursIntoDay(),
231230
day_seconds.getMinutesIntoHour(),
232231
day_seconds.getSecondsIntoMinute(),
233-
year_day.year,
232+
year_and_days.year,
234233
});
235234
}
236235

lib/std/crypto/Certificate.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ const Date = struct {
598598
var year: u16 = 1970;
599599
while (year < date.year) : (year += 1) {
600600
const days: u64 = std.time.epoch.getDaysInYear(year);
601-
sec += days * std.time.epoch.secs_per_day;
601+
sec += days * std.time.s_per_day;
602602
}
603603
}
604604

@@ -609,11 +609,11 @@ const Date = struct {
609609
date.year,
610610
@enumFromInt(month),
611611
);
612-
sec += days * std.time.epoch.secs_per_day;
612+
sec += days * std.time.s_per_day;
613613
}
614614
}
615615

616-
sec += (date.day - 1) * @as(u64, std.time.epoch.secs_per_day);
616+
sec += (date.day - 1) * @as(u64, std.time.s_per_day);
617617
sec += date.hour * @as(u64, 60 * 60);
618618
sec += date.minute * @as(u64, 60);
619619
sec += date.second;

0 commit comments

Comments
 (0)