From 5c508dbcc454618c733aebde4b9252c6b1868fea Mon Sep 17 00:00:00 2001 From: Alexander Barth Date: Thu, 5 Jul 2018 11:54:59 +0200 Subject: [PATCH] convert Float32 time variable to Float64 before converting them to DateTime --- src/time.jl | 5 +++++ test/test_time.jl | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/time.jl b/src/time.jl index 4b526976..f5dcf698 100644 --- a/src/time.jl +++ b/src/time.jl @@ -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)) diff --git a/test/test_time.jl b/test/test_time.jl index 3404775b..3bff3caa 100644 --- a/test/test_time.jl +++ b/test/test_time.jl @@ -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")