quinnj / Dates.jl

[DEPRECATED] Date/DateTime Implementation for the Julia Language; Successor to Datetime.jl
Other
8 stars 9 forks source link

Silent failure on conversion from string to DateTime #23

Open danluu opened 10 years ago

danluu commented 10 years ago

Should issues go here or directly to JuliaLang/julia now that this is in base? In any case, if you don't specify a format and your format doesn't match the default format, it's possible to get an incorrect result instead of an error.

julia> DateTime("2014")
ERROR: ArgumentError("Delimiter mismatch. Couldn't find first delimiter, \"-\", in date string")
 in parse at dates/io.jl:116
 in DateTime at dates/io.jl:162

julia> DateTime("2014-09")
2014-09-01T00:00:00

julia> DateTime("2014-09-06")
2014-09-06T00:00:00

julia> DateTime("2014-09-06 02:45:38")
2014-09-01T00:00:00

Of course this works fine if the correct format string is specified.

julia> DateTime("2014-09-06 02:45:38","y-m-d H:M:S")
2014-09-06T02:45:38
quinnj commented 10 years ago

Yeah, that is tricky. The whole providing-a-default format string has pretty much only led to problems, at least for DateTime. Maybe we get rid of it for DateTime and make the user supply the format string. Dates are much less prone to error, so maybe we can keep it there.

danluu commented 10 years ago

Yeah, I'd definitely prefer no default format over "random" silent failures. I haven't done ruby for at least 6 years, but my recollection was that their DateTime would often just magically get the right answer. That's probably pretty complicated and still somewhat error prone, though.