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

Proposal: Adding a nanosecond resolution now() #24

Open
p-casgrain opened this issue Sep 21, 2021 · 1 comment
Open

Proposal: Adding a nanosecond resolution now() #24

p-casgrain opened this issue Sep 21, 2021 · 1 comment

Comments

@p-casgrain
Copy link

p-casgrain commented Sep 21, 2021

I think it would be useful to add a higher-resolution version of Dates.now(). Possible implementation could be something like

function now_μs()
    tv = Libc.TimeVal()
    tm = Libc.TmStruct(tv.sec)
    return TimeDate(tm.year + 1900, tm.month + 1, Int64(tm.mday), Int64(tm.hour), Int64(tm.min), Int64(tm.sec)) + Microsecond(tv.usec)
end

which gives the current date/time to the microsecond level.

This expression gives it up to nanosecond resolution but in GMT time zone.

now_ns() = TimeDate(1970) + Nanosecond(time()*1e9)

I am not sure how to get in the system timezone.

If this is fine, I can make a PR with this bit inside.

@JeffreySarnoff
Copy link
Owner

please do

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

No branches or pull requests

2 participants