Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utimeSync truncates millisecond timestamps to nearest second #5065

Closed
srackham opened this issue May 4, 2020 · 0 comments · Fixed by #7299
Closed

utimeSync truncates millisecond timestamps to nearest second #5065

srackham opened this issue May 4, 2020 · 0 comments · Fixed by #7299
Labels
bug Something isn't working correctly cli related to cli/ dir public API related to "Deno" namespace in JS

Comments

@srackham
Copy link

srackham commented May 4, 2020

Deno statSync returns millisecond resolution but utimeSync truncates to seconds resolution.

Platform:

$ uname -a
Linux gnome-1804 4.15.0-99-generic #100-Ubuntu SMP Wed Apr 22 20:32:56 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

$ deno --version
deno 0.42.0
v8 8.2.308
typescript 3.8.3

In lieu of the REPL (#5063) I ran the following code:

const encoder = new TextEncoder();
const data = encoder.encode("foobar");

Deno.writeFileSync("test.txt", data);
console.log(`mtime: ${Deno.statSync("test.txt").mtime!.getTime()}`);
const newTime = 1588561654321;
console.log(`updating mtime to ${newTime}`);
Deno.utimeSync("test.txt", new Date(newTime), new Date(newTime));
console.log(`mtime: ${Deno.statSync("test.txt").mtime!.getTime()}`);

Output (the updated mtime is truncated to the nearest second):

mtime: 1588564365265
updating mtime to 1588561654321
mtime: 1588561654000

The Node.js utimesSync API does not exhibit this behaviour and sets millisecond timestamp resolution:

$ node --version
v13.14.0

$ node
Welcome to Node.js v13.14.0.
Type ".help" for more information.
> fs.writeFileSync('test.txt', 'foobar');
undefined
> fs.statSync('test.txt').mtime.getTime();
1588561704180
> fs.utimesSync('test.txt', new Date(1588561576064), new Date(1588561576064));
undefined
> fs.statSync('test.txt').mtime.getTime();
1588561576064
> 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly cli related to cli/ dir public API related to "Deno" namespace in JS
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants