Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Silent failure on conversion from string to DateTime #23

Open
danluu opened this issue Oct 4, 2014 · 2 comments
Open

Silent failure on conversion from string to DateTime #23

danluu opened this issue Oct 4, 2014 · 2 comments

Comments

@danluu
Copy link

danluu commented Oct 4, 2014

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
Copy link
Owner

quinnj commented Oct 6, 2014

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
Copy link
Author

danluu commented Oct 8, 2014

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants