Skip to content

fs.utimes arguments documentation #8638

@fcostarodrigo

Description

@fcostarodrigo

Could the documentation of fs.utimes (It says the type is Integer, and NaN or Infinity, will be converted to Date.now()) be more clear about the arguments? It looks like I can pass new Date(), but Date.now() needs to be divided by 1000. According to MDN Date.prototype.valueOf() and Date.now() both return: "The number of milliseconds between 1 January 1970 00:00:00 UTC and the given date.". It would be nice if the documentation mentioned that if the value is an Integer, it will be handled as a timestamp with precision of seconds.

var fs = require('fs');

fs.writeFileSync('test.txt', 'abc');
console.log('    ok', fs.statSync('test.txt').atime.getTime());

fs.utimesSync('test.txt', new Date(), new Date());
console.log('    ok', fs.statSync('test.txt').atime.getTime());

console.log('    ok', Date.now());

fs.utimesSync('test.txt', Date.now(), Date.now());
console.log('not ok', fs.statSync('test.txt').atime.getTime());

fs.utimesSync('test.txt', Date.now() / 1000, Date.now() / 1000);
console.log('    ok', fs.statSync('test.txt').atime.getTime());

Output

    ok 1474133782000
    ok 1474133783000
    ok 1474133783702
not ok 1474133783702000
    ok 1474133783000

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.fsIssues and PRs related to the fs subsystem / file system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions