From 61699e68bba5d1a8c6549093a1962ed0e2a8db6b Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 14 Jun 2019 23:05:04 +0800 Subject: [PATCH 1/2] 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 --- lib/internal/fs/utils.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 6cd6f7aceb2848..3470311e63807e 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 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); } From 9521cd965d807321532f2df487e3da2c4fea9cd9 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Mon, 17 Jun 2019 12:46:45 +0800 Subject: [PATCH 2/2] fixup! fs: document the Date conversion in Stats objects --- lib/internal/fs/utils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 3470311e63807e..24d946edf7288a 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -287,11 +287,11 @@ function nsFromTimeSpecBigInt(sec, nsec) { } // The Date constructor performs Math.floor() to the timestamp. -// https://www.ecma-international.org/ecma-262/#sec-timeclip +// 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 the timestamp here before passing it to Date(). -// Refs: https://github.com/nodejs/node/pull/12607 +// 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); }