quinnj / Datetime.jl

A Date and DateTime implementation for Julia; Now deprecated in favor of https://github.com/quinnj/Dates.jl
Other
20 stars 15 forks source link

Confusing "invalid digit error" in dt2string #37

Closed jiahao closed 10 years ago

jiahao commented 10 years ago

I'm not sure why the parsing is failing for these particular cases:

julia> Datetime.dt2string(Datetime.DateTimeFormat("mm/dd/yyyy"),"18/05/2009")
2009-01-05T00:18:00 UTC

julia> Datetime.dt2string(Datetime.DateTimeFormat("mm/dd/yyyy hh"),"18/05/2009 16")
2009-01-05T00:18:00 UTC

julia> Datetime.dt2string(Datetime.DateTimeFormat("mm/dd/yyyy hh:mm"),"18/05/2009 16:12")
ERROR: invalid base 10 digit '/' in "18/05/2009 16:12"
 in error at error.jl:21
 in int at string.jl:1519
 in dt2string at /Users/jiahao/.julia/Datetime/src/Datetime.jl:193

julia> Datetime.dt2string(Datetime.DateTimeFormat("mm:dd:yyyy"),"18:05:2009")
2009-01-05T00:18:00 UTC

julia> Datetime.dt2string(Datetime.DateTimeFormat("mm:dd:yyyy hh:mm"),"18:05:2009 16:12")
ERROR: invalid base 10 digit ':' in "18:05:2009 16:12"
 in error at error.jl:21
 in int at string.jl:1519
 in dt2string at /Users/jiahao/.julia/Datetime/src/Datetime.jl:193
jiahao commented 10 years ago

I realize now that MM is month and mm is minute. Oops

julia> Datetime.dt2string(Datetime.DateTimeFormat("MM:dd:yyyy hh:mm"),"08:05:2009 16:12")
2009-08-05T00:12:00 UTC
quinnj commented 10 years ago

Under the new parsing machinery I mentioned in the other issue, here are the outputs:

In  [15]: Datetime("18/05/2009","mm/dd/yyyy")

Out [15]: Month out of range
while loading In[15], in expression starting on line 1

In  [16]: Datetime("18/05/2009 16","mm/dd/yyyy hh")

Out [16]: Month out of range
while loading In[16], in expression starting on line 1

In  [17]: Datetime("18/05/2009 16:12","mm/dd/yyyy hh:mm")

Out [17]: Month out of range
while loading In[17], in expression starting on line 1

In  [18]: Datetime("18:05:2009","mm/dd/yyyy")

Out [18]: Month out of range
while loading In[18], in expression starting on line 1

In  [19]: Datetime("18/05/2009","dd/mm/yyyy")

Out [19]: 2009-05-18T00:00:00 UTC

In  [20]: Datetime("18/05/2009 16","dd/mm/yyyy HH")

Out [20]: 2009-05-18T16:00:00 UTC

In  [21]: Datetime("18/05/2009 16:12","dd/mm/yyyy HH:MM")

Out [21]: 2009-05-18T16:12:00 UTC

In  [22]: Datetime("18:05:2009","dd:mm:yyyy")

Out [22]: 2009-05-18T00:00:00 UTC

In  [23]: 

Clearly, we're doing better with the update on error messages.

quinnj commented 10 years ago

Fixed in new dev branch. ed8123ede2e316a181a781ecd54fd735657b6cd8