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

PR-URL: https://github.com/nodejs/node/pull/28224
Refs: https://github.com/nodejs/node/commit/ae6c7044c8d48cc8e7c267efca7429d5aa4df993
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>
This commit is contained in:
Joyee Cheung authored and Ruben Bridgewater committed 2019-09-03 14:14:02 +02:00
1 parent 365e062e14
commit e6353bda1a
1 file changed
+6
+6
View File
@@ -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);
}