choptastic / qdate

Erlang date, time, and timezone management: formatting, conversion, and date arithmetic
http://sigma-star.com/blog/post/qdate
MIT License
245 stars 82 forks source link

Get ISO8601 parsing working properly. #8

Open choptastic opened 10 years ago

davidw commented 10 years ago

This looks like it might be useful: https://github.com/seansawyer/erlang_iso8601/blob/master/LICENSE

choptastic commented 10 years ago

ec_date will, I believe, format and parse iso8601 properly already, but the key is ensuring it all plays nicely with qdate's timezone stuff.

davidw commented 10 years ago

I need to get something figured out sooner rather than later, and would like to pick one of these and implement it. This 8601 code is nice because it does just the one thing.

choptastic commented 10 years ago

Indeed. I'll be merging in your change CB for now, as it does the job.

Jesse Gumm Owner, Sigma Star Systems 414.940.4866 || sigma-star.com || @jessegumm On Aug 5, 2014 3:52 AM, "David N. Welton" notifications@github.com wrote:

I need to get something figured out sooner rather than later, and would like to pick one of these and implement it. This 8601 code is nice because it does just the one thing.

— Reply to this email directly or view it on GitHub https://github.com/choptastic/qdate/issues/8#issuecomment-51167183.

davidw commented 10 years ago

Well if there's some other code that's going to be used anyway, like qdate, perhaps this code could be stuffed in there (it's liberally licensed). Or maybe that can be the long term fix...

aramallo commented 9 years ago

This is what I am doing now :-)

date_parser() ->
    fun
        (RawDate) when length(RawDate) == 20 ->
            try 
                re:run(RawDate,"^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})Z",[{capture,all_but_first,list}]) 
            of
                nomatch -> undefined;
                {match, [Y,M,D,H,I,S]} ->
                    Date = {list_to_integer(Y), list_to_integer(M), list_to_integer(D)},
                    Time = {list_to_integer(H), list_to_integer(I), list_to_integer(S)},
                    case calendar:valid_date(Date) of
                        true -> 
                            {{Date, Time}, "UTC"};
                        false -> 
                            undefined
                    end
            catch 
                _:_ -> 
                    undefined
            end;
        (_) -> 
            undefined
    end.
qdate:register_parser(iso8601, date_parser()).
choptastic commented 9 years ago

Awesome! Thanks!

aramallo commented 9 years ago

Thanks to you! Awesome library :-)

On 9 Jul 2015, at 17:12, Jesse Gumm notifications@github.com wrote:

Awesome! Thanks!

— Reply to this email directly or view it on GitHub https://github.com/choptastic/qdate/issues/8#issuecomment-120052008.

erszcz commented 8 years ago

https://github.com/erlware/erlware_commons/pull/109 partially fixes ISO 8601 parsing in ec_date. Partially, because arbitrary fractions of a second aren't accepted, only 3 or 6 places after the comma which correspond to milli- and microseconds only up to 6 places after the comma, which correspond to microsecond precision.