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:ae6c7044c8
PR-URL: https://github.com/nodejs/node/pull/28224 Refs:ae6c7044c8
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:
parent
c72506c828
commit
b6326ce0f7
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user