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

File.mtime doesn't return milliseconds #2337

Closed
AlexWayfer opened this issue Apr 28, 2021 · 4 comments
Closed

File.mtime doesn't return milliseconds #2337

AlexWayfer opened this issue Apr 28, 2021 · 4 comments
Assignees
Milestone

Comments

@AlexWayfer
Copy link

truffleruby 21.1.0, like ruby 2.7.2, GraalVM CE Native [x86_64-linux]

Related:

@eregon
Copy link
Member

eregon commented Apr 28, 2021

Thank you for the report, I can reproduce:

ruby -e 'p File.mtime("README.md").to_f'   
1619184907.0575614
truffleruby -e 'p File.mtime("README.md").to_f'
1619184907.0

@AlexWayfer
Copy link
Author

Yep, sorry for a lack of example, I didn't know how to make it laconically.

@eregon
Copy link
Member

eregon commented Apr 28, 2021

We use struct stat.st_mtime and that's a number of seconds, but some platforms have struct stat.st_mtim which is a struct timespec.

buffer->mtime = native_stat->st_mtime;

If we store both seconds and nanonseconds into a uint64_t, then it would work until:

> Time.at((2 ** 64) / 1e9)
=> 2554-07-22 01:34:33 186005/262144 +0200

but not after.
So it's probably best to use an extra field for the nanoseconds.

We could store the nanoseconds of atime/mtime/ctime as 3 uint32_t fields at the end of the struct to avoid consuming a full uint64_t just for the nanoseconds.

@bjfish bjfish self-assigned this Apr 28, 2021
@bjfish
Copy link
Contributor

bjfish commented May 4, 2021

This is fixed at: fde89ae.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants