Skip to content

Commit 5c508db

Browse files
convert Float32 time variable to Float64 before converting them to DateTime
1 parent b8fec7a commit 5c508db

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/time.jl

+5
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,11 @@ function timeunits(units, calendar = "standard")
514514
return timeunits(DT,units)
515515
end
516516

517+
function timedecode(::Type{DT},data::AbstractArray{Float32,N},units) where {DT,N}
518+
# convert to Float64
519+
return timedecode(DT,Float64.(data),units)
520+
end
521+
517522
function timedecode(::Type{DT},data,units) where DT
518523
t0,plength = timeunits(DT,units)
519524
convert(x) = t0 + Dates.Millisecond(round(Int64,plength * x))

test/test_time.jl

+2
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ end
220220
[2455512.375]
221221

222222

223+
@test timedecode(DateTime,[22280.0f0],"days since 1950-01-01 00:00:00") == [DateTime(2011,1,1)]
224+
223225
@test_throws ErrorException timeencode(
224226
[DateTimeJulian(2010,10,29,9,0,0)],
225227
"days since -4713-01-01T00:00:00","360_day")

0 commit comments

Comments
 (0)