From 052b9799734c23588315d75c78bbdc4ec063a9d8 Mon Sep 17 00:00:00 2001 From: clickingbuttons Date: Thu, 11 Apr 2024 11:57:55 -0400 Subject: [PATCH] address @Vexu feedback --- lib/std/date/gregorian.zig | 14 +++++++------- lib/std/date_time.zig | 12 ++++++------ lib/std/time.zig | 6 ++++++ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/std/date/gregorian.zig b/lib/std/date/gregorian.zig index 2678fc426ec4..f30994bcd4c0 100644 --- a/lib/std/date/gregorian.zig +++ b/lib/std/date/gregorian.zig @@ -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; @@ -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); } @@ -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; diff --git a/lib/std/date_time.zig b/lib/std/date_time.zig index f54e43f45ea9..3b26345d0d74 100644 --- a/lib/std/date_time.zig +++ b/lib/std/date_time.zig @@ -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, @@ -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; diff --git a/lib/std/time.zig b/lib/std/time.zig index 10399be6c9fd..fabce5922480 100644 --- a/lib/std/time.zig +++ b/lib/std/time.zig @@ -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 {