Skip to content

Commit

Permalink
address @Vexu feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
clickingbuttons committed Apr 11, 2024
1 parent c41fdc0 commit 052b979
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
14 changes: 7 additions & 7 deletions lib/std/date/gregorian.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
/// To solve for `shift`, see `solve_shift`.
///
/// [1] https://onlinelibrary.wiley.com/doi/epdf/10.1002/spe.3172
const std = @import("std");
const IntFittingRange = std.math.IntFittingRange;
const secs_per_day = std.time.s_per_day;
const expectEqual = std.testing.expectEqual;
const assert = std.debug.assert;

pub fn DateAdvanced(comptime YearT: type, epoch_: comptime_int, shift: comptime_int) type {
// Zig's timestamp epoch is 1970-01-01. Ours is Mar 01, 0000 AD
const epoch = epoch_ + 719_468;
Expand Down Expand Up @@ -258,7 +264,7 @@ pub const WeekdayT = enum(WeekdayInt) {

pub const Int = WeekdayInt;

/// Convenient conversion to `WeekdayInt`. sun = 1, sat = 7
/// Convenient conversion to `WeekdayInt`. mon = 1, sun = 7
pub fn numeric(self: @This()) Int {
return @intFromEnum(self);
}
Expand Down Expand Up @@ -389,9 +395,3 @@ test solveShift {
try expectEqual(5_368_710, try solveShift(i32, 719_468));
try expectEqual(23_058_430_092_136_940, try solveShift(i64, 719_468));
}

const std = @import("std");
const IntFittingRange = std.math.IntFittingRange;
const secs_per_day = std.time.s_per_day;
const expectEqual = std.testing.expectEqual;
const assert = std.debug.assert;
12 changes: 6 additions & 6 deletions lib/std/date_time.zig
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
const std = @import("std.zig");
const date_mod = @import("./date.zig");
const time_mod = @import("./time.zig");
const s_per_day = time_mod.s_per_day;
const assert = std.debug.assert;

pub fn DateTimeAdvanced(comptime DateT: type, comptime TimeT: type) type {
return struct {
date: Date,
Expand Down Expand Up @@ -97,9 +103,3 @@ test "Date epoch" {
.date = .{ .year = std.math.maxInt(i16), .month = .dec, .day = 31 },
});
}

const std = @import("std.zig");
const date_mod = @import("./date.zig");
const time_mod = @import("./time.zig");
const s_per_day = time_mod.s_per_day;
const assert = std.debug.assert;
6 changes: 6 additions & 0 deletions lib/std/time.zig
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,12 @@ test Timer {
try testing.expect(timer.read() < time_1);
}

/// A time of day with a subsecond field capable of holding values
/// between 0 and 10 ** `precision_`.
///
/// Time(3) = milliseconds
/// Time(6) = microseconds
/// Time(9) = nanoseconds
pub fn Time(precision_: comptime_int) type {
const multiplier: comptime_int = try std.math.powi(usize, 10, precision_);
return struct {
Expand Down

0 comments on commit 052b979

Please sign in to comment.