Skip to content

Commit

Permalink
fs: document the Date conversion in Stats objects
Browse files Browse the repository at this point in the history
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]>
joyeecheung authored and BridgeAR committed Jun 17, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent c72506c commit b6326ce
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/internal/fs/utils.js
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit b6326ce

Please sign in to comment.