Skip to content

Commit

Permalink
src,fs: calculate fs times without truncation
Browse files Browse the repository at this point in the history
also added some missing bits that didn't make it into #12818

PR-URL: #12607
Refs: #12818
Reviewed-By: Timothy Gu <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
sciolist authored and jasnell committed May 28, 2017
1 parent 72a319e commit f077e51
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
8 changes: 4 additions & 4 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(s->st_##name.tv_sec) * 1000) + \
(static_cast<double>(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)
Expand Down
14 changes: 10 additions & 4 deletions test/parallel/test-fs-utimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
);
});
});
});
});
Expand Down

0 comments on commit f077e51

Please sign in to comment.