quinnj / Datetime.jl

A Date and DateTime implementation for Julia; Now deprecated in favor of https://github.com/quinnj/Dates.jl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Confusing "invalid digit error" in dt2string

jiahao opened this issue · comments

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

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

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.

Fixed in new dev branch. ed8123e