From f077e51c927bc3ee024695f1a8b336e5b7a514c6 Mon Sep 17 00:00:00 2001 From: Daniel Pihlstrom Date: Sun, 23 Apr 2017 01:55:35 -0400 Subject: [PATCH] src,fs: calculate fs times without truncation also added some missing bits that didn't make it into #12818 PR-URL: https://github.com/nodejs/node/pull/12607 Refs: https://github.com/nodejs/node/pull/12818 Reviewed-By: Timothy Gu Reviewed-By: Refael Ackermann Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- lib/fs.js | 8 ++++---- src/node_file.cc | 6 +++--- test/parallel/test-fs-utimes.js | 14 ++++++++++---- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index de5d6dcfb0fcbf..f6ea94e68fda5f 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -196,10 +196,10 @@ function Stats( this.ino = ino; this.size = size; this.blocks = blocks; - this.atime = new Date(atim_msec); - this.mtime = new Date(mtim_msec); - this.ctime = new Date(ctim_msec); - this.birthtime = new Date(birthtim_msec); + this.atime = new Date(atim_msec + 0.5); + this.mtime = new Date(mtim_msec + 0.5); + this.ctime = new Date(ctim_msec + 0.5); + this.birthtime = new Date(birthtim_msec + 0.5); } fs.Stats = Stats; diff --git a/src/node_file.cc b/src/node_file.cc index c0343fbf00200d..6d07a0625944fd 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -479,9 +479,9 @@ void FillStatsArray(double* fields, const uv_stat_t* s) { fields[9] = -1; #endif // Dates. -#define X(idx, name) \ - fields[idx] = (static_cast(s->st_##name.tv_sec) * 1000) + \ - (static_cast(s->st_##name.tv_nsec / 1000000)); \ +#define X(idx, name) \ + fields[idx] = (s->st_##name.tv_sec * 1e3) + \ + (s->st_##name.tv_nsec / 1e6); \ X(10, atim) X(11, mtim) diff --git a/test/parallel/test-fs-utimes.js b/test/parallel/test-fs-utimes.js index 456f09b8041cb6..f5eaf282f59ad0 100644 --- a/test/parallel/test-fs-utimes.js +++ b/test/parallel/test-fs-utimes.js @@ -143,15 +143,21 @@ function testIt(atime, mtime, callback) { const stats = fs.statSync(__filename); // run tests -const runTest = common.mustCall(testIt, 5); +const runTest = common.mustCall(testIt, 6); runTest(new Date('1982-09-10 13:37'), new Date('1982-09-10 13:37'), function() { runTest(new Date(), new Date(), function() { runTest(123456.789, 123456.789, function() { runTest(stats.mtime, stats.mtime, function() { - runTest('123456', -1, common.mustCall(function() { - // done - })); + runTest('123456', -1, function() { + runTest( + new Date('2017-04-08T17:59:38.008Z'), + new Date('2017-04-08T17:59:38.008Z'), + common.mustCall(function() { + // done + }) + ); + }); }); }); });