Skip to content

Commit

Permalink
Fix datetime (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
bicycle1885 authored Jun 5, 2019
1 parent f8c4dd4 commit 57a39c2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/TableReader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 57a39c2

Please sign in to comment.