diff --git a/src/TableReader.jl b/src/TableReader.jl index b45f8d9..fa5bc95 100644 --- a/src/TableReader.jl +++ b/src/TableReader.jl @@ -531,7 +531,7 @@ function readdlm_internal(stream::TranscodingStream, params::LexerParameters) # not a date column end elseif is_datetime_like(col) - hasT = occursin('T', col[1]) # check delimited by T or space + hasT = is_T_delimited(col) # check delimited by T or space try columns[i] = parse_datetime(col, hasT) catch diff --git a/src/parser.jl b/src/parser.jl index 76dd75d..75d38b9 100644 --- a/src/parser.jl +++ b/src/parser.jl @@ -267,6 +267,15 @@ function parse_datetime(s::String, hasT::Bool) end end +function is_T_delimited(col::Vector{<:Union{String,Missing}}) + for x in col + if !Base.ismissing(x) + return occursin('T', x) + end + end + return false +end + function is_datetime_like(col::Vector{<:Union{String,Missing}}) # Check if the first three strings (if any) are datetime-like. i = 1 diff --git a/test/runtests.jl b/test/runtests.jl index 7ba580d..121984d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -854,6 +854,18 @@ end """ @test_throws TableReader.ReadError("invalid file format at line 2, column 1 (found 0xff)") readtsv(IOBuffer(data), quot = nothing) end + + @testset "datetimes" begin + buf = IOBuffer(""" + col1,col2 + 1, + 2,2018-04-10T08:19:30.000 + """) + df = readcsv(buf) + @test df[:col1] == [1, 2] + @test ismissing(df[1,:col2]) + @test df[2,:col2] == DateTime(2018, 4, 10, 8, 19, 30) + end end @testset "readdlm" begin