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

Support nanosecond timestamps (from/to) #44

Closed
rbeeli opened this issue Jul 7, 2024 · 6 comments
Closed

Support nanosecond timestamps (from/to) #44

rbeeli opened this issue Jul 7, 2024 · 6 comments

Comments

@rbeeli
Copy link

rbeeli commented Jul 7, 2024

If I read the docs correctly, there is no support for constructing a NanoDate from a UNIX timestamp in nanoseconds, and also no function to convert a NanoDate to an Int64 representing nanoseconds since epoch.

Is this correct? If so, could support for this be added?

@rbeeli
Copy link
Author

rbeeli commented Jul 7, 2024

Ok, I was to fast with my conclusion, it just wasn't clear from the docs, maybe this could be added? It shows something under "Technical: unexported", but Dates.value is exported/accessible.

julia> NanoDate(2024,7, 7)
2024-07-07T00:00:00

julia> Dates.value(NanoDate(2024,7, 7))
63855993600000000000

julia> NanoDate(63855993600000000000)
2024-07-07T00:00:00

Also, there is nanodate2unixnanos, but not listed in the docs.

@rbeeli
Copy link
Author

rbeeli commented Jul 7, 2024

Actually, these methods do not represent the nanoseconds timestamp since epoch, is this correct?

The nanosecond UNIX timestamp for 2024-07-07 should be 1720310400000000000, not 63855993600000000000.

@JeffreySarnoff
Copy link
Member

the methods you want already exist, although we use Integers as Float64s are not resolute enough

julia> using Dates, NanoDates
julia> using NanoDates: nanodate2unixnanos, unixnanos2nanodate


julia> nd1 = NanoDate("2024-07-07")
2024-07-07T00:00:00

julia> nd2 = NanoDate("2024-07-07T00:00:00.000000001")
2024-07-07T00:00:00.000000001

julia> und1 = nanodate2unixnanos(nd1)
1720310400000000000

julia> und2 = nanodate2unixnanos(nd2)
1720310400000000001

julia> unixnanos2nanodate(und1)
2024-07-07T00:00:00

julia> unixnanos2nanodate(und2)
2024-07-07T00:00:00.000000001

see src/conversions.jl for other, similar conversions

@rbeeli
Copy link
Author

rbeeli commented Aug 13, 2024

Thanks @JeffreySarnoff. How about adding it to the docs, i.e. nanodate2unixnanos and unixnanos2nanodate?

@JeffreySarnoff
Copy link
Member

JeffreySarnoff commented Aug 13, 2024 via email

@JeffreySarnoff
Copy link
Member

JeffreySarnoff commented Aug 13, 2024 via email

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