dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.29k stars 1.59k forks source link

File stat() modtime precision doesn't seem to include microseconds/nanoseconds #56626

Open tomekit opened 2 months ago

tomekit commented 2 months ago

I am calling statSync() on file and getting modtime with ms precision: 2024-09-02 09:57:59.602.

If I call bash CLI: stat <filename> I get full ns precision: 2024-09-02 09:57:59.602813345. I am using EXT4 filesystem.

By any chance is it possible to get the modtime with full available precision down to the nanosecond?

Dart/Flutter statSync(): Screenshot from 2024-09-02 10-03-02

Bash stat: Screenshot from 2024-09-02 10-03-29

dart-github-bot commented 2 months ago

Summary: The statSync() method in Dart returns the file modification time with millisecond precision, while the stat command in bash provides nanosecond precision. The user requests support for retrieving the modification time with full nanosecond precision in Dart.

a-siva commented 2 months ago

@tomekit supporting precision down to the nanosecond would mean we would have to change Dart's DateTime class (https://api.flutter.dev/flutter/dart-core/DateTime-class.html) to include a DateTime.fromNanosecondsSinceEpoch class. This is a breaking change. A much easier change would be for us to support microseconds precision from the statSync call, this would be supported on platforms that support microsecond precision from the stat call (linux, macos..) and on windows we would still maintain the millisecond precision as the _wstat64 call on Windows only supports that.