diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-05-24 20:06:56 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-05-24 21:40:08 -0400 |
| commit | 53d011fa1a7bfb2389e3677e1f6fcbe7a678e05f (patch) | |
| tree | 6dc248d8606088f7a288c00f6ccef78290229cf4 /lib/std/fs | |
| parent | c6e7d0fcfdf83531c5c931433528c540eee62e56 (diff) | |
| download | zig-53d011fa1a7bfb2389e3677e1f6fcbe7a678e05f.tar.gz zig-53d011fa1a7bfb2389e3677e1f6fcbe7a678e05f.zip | |
(breaking) std.time fixups and API changes
Remove the constants that assume a base unit in favor of explicit
x_per_y constants.
nanosecond calendar timestamps now use i128 for the type. This affects
fs.File.Stat, std.time.nanoTimestamp, and fs.File.updateTimes.
calendar timestamps are now signed, because the value can be less than
the epoch (the user can set their computer time to whatever they wish).
implement std.os.clock_gettime for Windows when clock id is
CLOCK_CALENDAR.
Diffstat (limited to 'lib/std/fs')
| -rw-r--r-- | lib/std/fs/file.zig | 24 | ||||
| -rw-r--r-- | lib/std/fs/test.zig | 6 |
2 files changed, 14 insertions, 16 deletions
diff --git a/lib/std/fs/file.zig b/lib/std/fs/file.zig index f8cf69cbb8..a9ee996e4b 100644 --- a/lib/std/fs/file.zig +++ b/lib/std/fs/file.zig @@ -227,14 +227,12 @@ pub const File = struct { size: u64, mode: Mode, - /// access time in nanoseconds - atime: i64, - - /// last modification time in nanoseconds - mtime: i64, - - /// creation time in nanoseconds - ctime: i64, + /// Access time in nanoseconds, relative to UTC 1970-01-01. + atime: i128, + /// Last modification time in nanoseconds, relative to UTC 1970-01-01. + mtime: i128, + /// Creation time in nanoseconds, relative to UTC 1970-01-01. + ctime: i128, }; pub const StatError = os.FStatError; @@ -270,9 +268,9 @@ pub const File = struct { .inode = st.ino, .size = @bitCast(u64, st.size), .mode = st.mode, - .atime = @as(i64, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec, - .mtime = @as(i64, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec, - .ctime = @as(i64, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec, + .atime = @as(i128, atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec, + .mtime = @as(i128, mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec, + .ctime = @as(i128, ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec, }; } @@ -286,9 +284,9 @@ pub const File = struct { pub fn updateTimes( self: File, /// access timestamp in nanoseconds - atime: i64, + atime: i128, /// last modification timestamp in nanoseconds - mtime: i64, + mtime: i128, ) UpdateTimesError!void { if (builtin.os.tag == .windows) { const atime_ft = windows.nanoSecondsToFileTime(atime); diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index a857c3a7f8..2d979f5690 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -10,7 +10,7 @@ test "openSelfExe" { self_exe_file.close(); } -const FILE_LOCK_TEST_SLEEP_TIME = 5 * std.time.millisecond; +const FILE_LOCK_TEST_SLEEP_TIME = 5 * std.time.ns_per_ms; test "open file with exclusive nonblocking lock twice" { if (builtin.os.tag == .wasi) return error.SkipZigTest; @@ -142,8 +142,8 @@ const FileLockTestContext = struct { // Output variables err: ?(File.OpenError || std.os.ReadError) = null, - start_time: u64 = 0, - end_time: u64 = 0, + start_time: i64 = 0, + end_time: i64 = 0, bytes_read: ?usize = null, fn overlaps(self: *const @This(), other: *const @This()) bool { |
