Skip to content

Commit e6353bd

Browse files
joyeecheungBridgeAR
authored andcommitted
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 365e062 commit e6353bd

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/internal/fs/utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ function nsFromTimeSpecBigInt(sec, nsec) {
287287
return sec * kNsPerSecBigInt + nsec;
288288
}
289289

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

0 commit comments

Comments
 (0)