Skip to content

Commit

Permalink
convert Float32 time variable to Float64 before converting them to Da…
Browse files Browse the repository at this point in the history
…teTime
  • Loading branch information
Alexander-Barth committed Jul 5, 2018
1 parent b8fec7a commit 5c508db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/time.jl
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,11 @@ function timeunits(units, calendar = "standard")
return timeunits(DT,units)
end

function timedecode(::Type{DT},data::AbstractArray{Float32,N},units) where {DT,N}
# convert to Float64
return timedecode(DT,Float64.(data),units)
end

function timedecode(::Type{DT},data,units) where DT
t0,plength = timeunits(DT,units)
convert(x) = t0 + Dates.Millisecond(round(Int64,plength * x))
Expand Down
2 changes: 2 additions & 0 deletions test/test_time.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ end
[2455512.375]


@test timedecode(DateTime,[22280.0f0],"days since 1950-01-01 00:00:00") == [DateTime(2011,1,1)]

@test_throws ErrorException timeencode(
[DateTimeJulian(2010,10,29,9,0,0)],
"days since -4713-01-01T00:00:00","360_day")
Expand Down

0 comments on commit 5c508db

Please sign in to comment.