Skip to content
Permalink
Browse files

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 <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>
  • Loading branch information...
joyeecheung authored and BridgeAR committed Jun 14, 2019
1 parent 365e062 commit e6353bda1a1efe2e178caba523c26435c96751e4
Showing with 6 additions and 0 deletions.
  1. +6 −0 lib/internal/fs/utils.js
@@ -287,6 +287,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 e6353bd

Please sign in to comment.
You can’t perform that action at this time.