Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e89a39b

Browse files
joyeecheungBridgeAR
authored andcommittedJun 17, 2019
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: ae6c704 PR-URL: #28224 Refs: ae6c704 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 366c983 commit e89a39b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed
 

‎lib/internal/fs/utils.js

+6
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ function nsFromTimeSpecBigInt(sec, nsec) {
286286
return sec * kNsPerSecBigInt + nsec;
287287
}
288288

289+
// The Date constructor performs Math.floor() to the timestamp.
290+
// https://www.ecma-international.org/ecma-262/#sec-timeclip
291+
// Since there may be a precision loss when the timestamp is
292+
// converted to a floating point number, we manually round
293+
// the timestamp here before passing it to Date().
294+
// Refs: https://github.com/nodejs/node/pull/12607
289295
function dateFromMs(ms) {
290296
return new Date(Number(ms) + 0.5);
291297
}

0 commit comments

Comments
 (0)
Please sign in to comment.