diff options
author | Casper Beyer <caspervonb@pm.me> | 2020-09-01 22:03:07 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-01 10:03:07 -0400 |
commit | 87e513ffc5d9c14ac4af6a893b9e862c55108bea (patch) | |
tree | af8c84de948890e7c55b13ab53bd7a03c08a75ca /cli/rt/30_fs.js | |
parent | 644190eed862c2224630dd68404a5fd6e2e30440 (diff) |
fix: use millisecond precision for Deno.futime and Deno.utime (#7299)
Diffstat (limited to 'cli/rt/30_fs.js')
-rw-r--r-- | cli/rt/30_fs.js | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/cli/rt/30_fs.js b/cli/rt/30_fs.js index 750c3c1ba..df91d767f 100644 --- a/cli/rt/30_fs.js +++ b/cli/rt/30_fs.js @@ -264,8 +264,25 @@ await sendAsync("op_link_async", { oldpath, newpath }); } - function toSecondsFromEpoch(v) { - return v instanceof Date ? Math.trunc(v.valueOf() / 1000) : v; + function toUnixTimeFromEpoch(value) { + if (value instanceof Date) { + const time = value.valueOf(); + const seconds = Math.trunc(time / 1e3); + const nanoseconds = Math.trunc(time - (seconds * 1e3)) * 1e6; + + return [ + seconds, + nanoseconds, + ]; + } + + const seconds = value; + const nanoseconds = 0; + + return [ + seconds, + nanoseconds, + ]; } function futimeSync( @@ -275,9 +292,8 @@ ) { sendSync("op_futime_sync", { rid, - // TODO(caspervonb) split atime, mtime into [seconds, nanoseconds] tuple - atime: toSecondsFromEpoch(atime), - mtime: toSecondsFromEpoch(mtime), + atime: toUnixTimeFromEpoch(atime), + mtime: toUnixTimeFromEpoch(mtime), }); } @@ -288,9 +304,8 @@ ) { await sendAsync("op_futime_async", { rid, - // TODO(caspervonb) split atime, mtime into [seconds, nanoseconds] tuple - atime: toSecondsFromEpoch(atime), - mtime: toSecondsFromEpoch(mtime), + atime: toUnixTimeFromEpoch(atime), + mtime: toUnixTimeFromEpoch(mtime), }); } @@ -301,9 +316,8 @@ ) { sendSync("op_utime_sync", { path, - // TODO(ry) split atime, mtime into [seconds, nanoseconds] tuple - atime: toSecondsFromEpoch(atime), - mtime: toSecondsFromEpoch(mtime), + atime: toUnixTimeFromEpoch(atime), + mtime: toUnixTimeFromEpoch(mtime), }); } @@ -314,9 +328,8 @@ ) { await sendAsync("op_utime_async", { path, - // TODO(ry) split atime, mtime into [seconds, nanoseconds] tuple - atime: toSecondsFromEpoch(atime), - mtime: toSecondsFromEpoch(mtime), + atime: toUnixTimeFromEpoch(atime), + mtime: toUnixTimeFromEpoch(mtime), }); } |