Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flexible date parsing #13

Open
femtotrader opened this issue May 22, 2016 · 0 comments
Open

Flexible date parsing #13

femtotrader opened this issue May 22, 2016 · 0 comments

Comments

@femtotrader
Copy link
Collaborator

femtotrader commented May 22, 2016

Should we use flexible date parsing ?

see http://comments.gmane.org/gmane.comp.lang.julia.user/36468

julia> length(long_list_of_date_strs)
497338

julia> function find_matching_datetime_format(datestr)
           datestr = strip(datestr)
           formats = ["y-m-d H:M", "y/m/d H:M", "y m d H:M"] # Add more formats as needed...
           for ft in formats
               try
                   d = Dates.DateTime(datestr, ft)
                   return d, ft
               catch err
               end
           end
           throw("Cannot find a date format that matches: $(datestr)")
       end
find_matching_datetime_format (generic function with 1 method)

julia> parsedate(s) = find_matching_datetime_format(s)[1]
parsedate (generic function with 1 method)

julia> function parsedates(datestrings)
           d, ftstr = find_matching_datetime_format(datestrings[1])
           ft = Dates.DateFormat(ftstr)
           map(ds -> Dates.DateTime(ds, ft), datestrings)
       end
parsedates (generic function with 1 method)

julia> <at> time r1 = map(parsedate, long_list_of_date_strs[1:10000]);
elapsed time: 3.507318034 seconds (273707960 bytes allocated, 41.44% gc time)

julia> <at> time r2 = parsedates(long_list_of_date_strs[1:10000]);
elapsed time: 0.325861155 seconds (38314796 bytes allocated, 72.21% gc time)

julia> r1 == r2
true

For millisecond resolution

julia> DateTime("20151125 04:07:35.919", "yyyymmdd HH:MM:SS.sss")
2015-11-25T04:07:35.919
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant