aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-06-14 23:05:04 +0800
committerRuben Bridgewater <ruben@bridgewater.de>2019-06-17 11:54:34 +0200
commitb6326ce0f7317ea92313de5acff221deced9eb51 (patch)
tree116316499bd1f919b6293272b758b8e1700cb195
parentc72506c828be158bb149fe4e8662e0f0cf1dffdf (diff)
downloadandroid-node-v8-b6326ce0f7317ea92313de5acff221deced9eb51.tar.gz
android-node-v8-b6326ce0f7317ea92313de5acff221deced9eb51.tar.bz2
android-node-v8-b6326ce0f7317ea92313de5acff221deced9eb51.zip
fs: document the Date conversion in Stats objects
Document why the dates are calculated with the timestamp in Numbers + 0.5. The comment was previously lost in a revert. Refs: https://github.com/nodejs/node/commit/ae6c7044c8d48cc8e7c267efca7429d5aa4df993 PR-URL: https://github.com/nodejs/node/pull/28224 Refs: https://github.com/nodejs/node/commit/ae6c7044c8d48cc8e7c267efca7429d5aa4df993 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
-rw-r--r--lib/internal/fs/utils.js6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js
index 6cd6f7aceb..24d946edf7 100644
--- a/lib/internal/fs/utils.js
+++ b/lib/internal/fs/utils.js
@@ -286,6 +286,12 @@ function nsFromTimeSpecBigInt(sec, nsec) {
return sec * kNsPerSecBigInt + nsec;
}
+// The Date constructor performs Math.floor() to the timestamp.
+// https://www.ecma-international.org/ecma-262/#sec-timeclip
+// Since there may be a precision loss when the timestamp is
+// converted to a floating point number, we manually round
+// the timestamp here before passing it to Date().
+// Refs: https://github.com/nodejs/node/pull/12607
function dateFromMs(ms) {
return new Date(Number(ms) + 0.5);
}