Skip to content

Commit

Permalink
[sqwsh] Y2K38 Test for all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
refack committed Jun 1, 2017
1 parent 0d96575 commit 342c2e2
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions test/parallel/test-fs-utimes.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,30 @@ runTest(new Date('1982-09-10 13:37'), new Date('1982-09-10 13:37'), function() {
});
});

process.on('exit', function() {
assert.strictEqual(tests_ok, tests_run);
});


// Ref: https://github.com/nodejs/node/issues/13255
if (common.isWindows) {
common.refreshTmpDir();
const path = `${common.tmpDir}/test-utimes-precision`;
fs.writeFileSync(path, '');
common.refreshTmpDir();
const path = `${common.tmpDir}/test-utimes-precision`;
fs.writeFileSync(path, '');

// test Y2K38 for all platforms
const Y2K38_mtime = 2**31;
fs.utimesSync(path, Y2K38_mtime, Y2K38_mtime);
const Y2K38_stats = fs.statSync(path);
assert.strictEqual(Y2K38_mtime, Y2K38_stats.mtime.getTime() / 1000);

if (common.isWindows) {
// this value would get converted to (double)1713037251359.9998
const truncate_mtime = 1713037251360;
fs.utimesSync(path, truncate_mtime / 1000, truncate_mtime / 1000);
const truncate_stats = fs.statSync(path);
assert.strictEqual(truncate_mtime, truncate_stats.mtime.getTime());

// test Y2K38 for windows
// This value if treaded as a `signed long` gets converted to -2135622133469.
// POSIX systems stores timestamps in {long t_sec, long t_usec}.
// NTFS stores times in nanoseconds in a single `uint64_t`, so when libuv
Expand All @@ -184,7 +196,3 @@ if (common.isWindows) {
const overflow_stats = fs.statSync(path);
assert.strictEqual(overflow_mtime, overflow_stats.mtime.getTime());
}

process.on('exit', function() {
assert.strictEqual(tests_ok, tests_run);
});

0 comments on commit 342c2e2

Please sign in to comment.