Skip to content

Commit 25dbcb5

Browse files
address FObersteiner feedback
1 parent 423cb31 commit 25dbcb5

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

lib/std/date_time.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,24 @@ pub fn DateTime(comptime DateT: type, comptime TimeT: type) type {
1212
/// 9 = nanoseconds
1313
pub const EpochSubseconds = std.meta.Int(
1414
@typeInfo(Date.EpochDays).Int.signedness,
15-
@typeInfo(Date.EpochDays).Int.bits + std.math.log2_int_ceil(usize, Time.fs_per_day),
15+
@typeInfo(Date.EpochDays).Int.bits + std.math.log2_int_ceil(usize, Time.subseconds_per_day),
1616
);
1717

1818
const Self = @This();
1919

20-
/// New date time from fractional epoch seconds.
20+
/// New date time from fractional seconds since `Date.epoch`.
2121
pub fn fromEpoch(subseconds: EpochSubseconds, time_opts: Time.Options) Self {
22-
const days = @divFloor(subseconds, s_per_day * Time.fs_per_s);
22+
const days = @divFloor(subseconds, s_per_day * Time.subseconds_per_s);
2323
const new_date = Date.fromEpoch(@intCast(days));
24-
const day_seconds = std.math.comptimeMod(subseconds, s_per_day * Time.fs_per_s);
24+
const day_seconds = std.math.comptimeMod(subseconds, s_per_day * Time.subseconds_per_s);
2525
const new_time = Time.fromDaySeconds(day_seconds, time_opts);
2626
return .{ .date = new_date, .time = new_time };
2727
}
2828

29-
/// Returns fractional epoch seconds.
29+
/// Returns fractional seconds since `Date.epoch`.
3030
pub fn toEpoch(self: Self) EpochSubseconds {
3131
var res: EpochSubseconds = 0;
32-
res += @as(EpochSubseconds, self.date.toEpoch()) * s_per_day * Time.fs_per_s;
32+
res += @as(EpochSubseconds, self.date.toEpoch()) * s_per_day * Time.subseconds_per_s;
3333
res += self.time.toDaySeconds();
3434
return res;
3535
}

lib/std/time.zig

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -367,27 +367,27 @@ pub fn Time(precision_: comptime_int, comptime has_offset: bool) type {
367367
const Self = @This();
368368

369369
pub const precision = precision_;
370-
pub const fs_per_s = multiplier;
371-
pub const fs_per_min = 60 * fs_per_s;
372-
pub const fs_per_hour = 60 * fs_per_min;
373-
pub const fs_per_day = 24 * fs_per_hour;
370+
pub const subseconds_per_s = multiplier;
371+
pub const subseconds_per_min = 60 * subseconds_per_s;
372+
pub const subseconds_per_hour = 60 * subseconds_per_min;
373+
pub const subseconds_per_day = 24 * subseconds_per_hour;
374374

375375
pub const Options = struct {
376376
offset: IMinutes = 0,
377377
};
378378

379379
pub fn fromDaySeconds(seconds: DaySubseconds, options: Options) Self {
380-
const fs_offset = @as(IDaySubseconds, options.offset) * fs_per_min + seconds;
381-
var fs = std.math.comptimeMod(fs_offset, fs_per_day);
380+
const fs_offset = @as(IDaySubseconds, options.offset) * subseconds_per_min + seconds;
381+
var fs = std.math.comptimeMod(fs_offset, subseconds_per_day);
382382

383-
const hour: Hour = @intCast(@divFloor(fs, fs_per_hour));
384-
fs -= @as(DaySubseconds, @intCast(hour)) * fs_per_hour;
383+
const hour: Hour = @intCast(@divFloor(fs, subseconds_per_hour));
384+
fs -= @as(DaySubseconds, @intCast(hour)) * subseconds_per_hour;
385385

386-
const minute: Minute = @intCast(@divFloor(fs, fs_per_min));
387-
fs -= @as(DaySubseconds, @intCast(minute)) * fs_per_min;
386+
const minute: Minute = @intCast(@divFloor(fs, subseconds_per_min));
387+
fs -= @as(DaySubseconds, @intCast(minute)) * subseconds_per_min;
388388

389-
const second: Second = @intCast(@divFloor(fs, fs_per_s));
390-
fs -= @as(DaySubseconds, @intCast(second)) * fs_per_s;
389+
const second: Second = @intCast(@divFloor(fs, subseconds_per_s));
390+
fs -= @as(DaySubseconds, @intCast(second)) * subseconds_per_s;
391391

392392
return .{
393393
.hour = hour,
@@ -404,9 +404,9 @@ pub fn Time(precision_: comptime_int, comptime has_offset: bool) type {
404404

405405
pub fn toDaySecondsZone(self: Self, zone: IMinutes) DaySubseconds {
406406
var sec = @as(IDaySubseconds, zone) * 60 * multiplier;
407-
sec += @as(IDaySubseconds, self.hour) * fs_per_hour;
408-
sec += @as(IDaySubseconds, self.minute) * fs_per_min;
409-
sec += @as(IDaySubseconds, self.second) * fs_per_s;
407+
sec += @as(IDaySubseconds, self.hour) * subseconds_per_hour;
408+
sec += @as(IDaySubseconds, self.minute) * subseconds_per_min;
409+
sec += @as(IDaySubseconds, self.second) * subseconds_per_s;
410410
sec += @as(IDaySubseconds, self.subsecond);
411411

412412
return std.math.comptimeMod(sec, s_per_day * multiplier);

0 commit comments

Comments
 (0)