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

Timestamp data should be more precise #11

Open
tk3369 opened this issue Dec 29, 2017 · 1 comment
Open

Timestamp data should be more precise #11

tk3369 opened this issue Dec 29, 2017 · 1 comment

Comments

@tk3369
Copy link
Owner

tk3369 commented Dec 29, 2017

This code could be improved as x[i] is a floating point value of # of seconds since epoch. By multiplying it by 1e3 or 1e6 would allow us to read the data as in millisecond/microseconds. Need to cross check what precision SAS can support.

# convert Float64 value into DateTime object 
function datetime_from_float(x::Vector{Float64})
    v = Vector{Union{DateTime, Missing}}(length(x))
    for i in 1:length(x)
        v[i] = isnan(x[i]) ? missing : (sas_datetime_origin + Dates.Second(round(Int64, x[i])))
    end
    v
end
@tbeason
Copy link
Contributor

tbeason commented May 18, 2021

Following up on this, I made a function that helped me, maybe it could be useful here. It only covers the case of Time columns (not DateTime)

seconds2time(t) = Time(Nanosecond(round(t,digits=9) * 1e9))
julia> seconds2time(34200)
09:30:00

julia> seconds2time(34200.0356466666)
09:30:00.035646667

I explicitly round it to nanoseconds because that is the smallest unit that the Dates.jl standard library supports. This is likely sufficient for most usage, I'd guess.

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

2 participants