Skip to content

Commit f077e51

Browse files
sciolistjasnell
authored andcommitted
src,fs: calculate fs times without truncation
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]>
1 parent 72a319e commit f077e51

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

Diff for: lib/fs.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ function Stats(
196196
this.ino = ino;
197197
this.size = size;
198198
this.blocks = blocks;
199-
this.atime = new Date(atim_msec);
200-
this.mtime = new Date(mtim_msec);
201-
this.ctime = new Date(ctim_msec);
202-
this.birthtime = new Date(birthtim_msec);
199+
this.atime = new Date(atim_msec + 0.5);
200+
this.mtime = new Date(mtim_msec + 0.5);
201+
this.ctime = new Date(ctim_msec + 0.5);
202+
this.birthtime = new Date(birthtim_msec + 0.5);
203203
}
204204
fs.Stats = Stats;
205205

Diff for: src/node_file.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,9 @@ void FillStatsArray(double* fields, const uv_stat_t* s) {
479479
fields[9] = -1;
480480
#endif
481481
// Dates.
482-
#define X(idx, name) \
483-
fields[idx] = (static_cast<double>(s->st_##name.tv_sec) * 1000) + \
484-
(static_cast<double>(s->st_##name.tv_nsec / 1000000)); \
482+
#define X(idx, name) \
483+
fields[idx] = (s->st_##name.tv_sec * 1e3) + \
484+
(s->st_##name.tv_nsec / 1e6); \
485485

486486
X(10, atim)
487487
X(11, mtim)

Diff for: test/parallel/test-fs-utimes.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,21 @@ function testIt(atime, mtime, callback) {
143143
const stats = fs.statSync(__filename);
144144

145145
// run tests
146-
const runTest = common.mustCall(testIt, 5);
146+
const runTest = common.mustCall(testIt, 6);
147147

148148
runTest(new Date('1982-09-10 13:37'), new Date('1982-09-10 13:37'), function() {
149149
runTest(new Date(), new Date(), function() {
150150
runTest(123456.789, 123456.789, function() {
151151
runTest(stats.mtime, stats.mtime, function() {
152-
runTest('123456', -1, common.mustCall(function() {
153-
// done
154-
}));
152+
runTest('123456', -1, function() {
153+
runTest(
154+
new Date('2017-04-08T17:59:38.008Z'),
155+
new Date('2017-04-08T17:59:38.008Z'),
156+
common.mustCall(function() {
157+
// done
158+
})
159+
);
160+
});
155161
});
156162
});
157163
});

0 commit comments

Comments
 (0)