Repository navigation
Open
Labels
staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Description
Version
v22.16.0
Platform
Linux johnp-pc 7.1.3-200.fc44.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Jul 4 19:20:12 UTC 2026 x86_64 GNU/Linux
Subsystem
node:fs
What steps will reproduce the bug?
Description
Since 1f842c2, NodeJS internally modifies numeric negative utimes to the current time. This is unexpected, as negative strings ("-1") work as expected. This issue was previously reported, but not all possible types (date, string, number) were considered. and the bug therefore wrongly closed.
Reproducer
import fs from 'node:fs';
const file = 'neg_timespec.txt';
fs.writeFileSync(file, 'test');
// Set time to -1 second before 1970
fs.utimesSync(file, -1, -1);
const stats = fs.statSync(file);
console.log("Expected mtime (ms): -1000");
console.log("Actual mtime (ms): ", stats.mtime.getTime());
fs.unlinkSync(file);Incorrect code
Lines 783 to 793 in 4f844f4
| function toUnixTimestamp(time, name = 'time') { | |
| // eslint-disable-next-line eqeqeq | |
| if (typeof time === 'string' && +time == time) { | |
| return +time; | |
| } | |
| if (NumberIsFinite(time)) { | |
| if (time < 0) { | |
| return DateNow() / 1000; | |
| } | |
| return time; | |
| } |
How often does it reproduce? Is there a required condition?
100%
What is the expected behavior? Why is that the expected behavior?
Expected mtime (ms): -1500
What do you see instead?
Actual mtime (ms): 1784465433024
Additional information
Found investigating the Rust port of Bun, where the bug was copied by AI presumably.
Metadata
Metadata
Assignees
Labels
staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
Activity
[-]fs: incorrect handling numeric times from before the unix epoch[/-][+]fs: incorrect handling of numeric times from before the unix epoch[/+]github-actions commentedon Oct 18, 2026
This issue has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.