qdate icon indicating copy to clipboard operation
qdate copied to clipboard

Get ISO8601 parsing working properly.

Open choptastic opened this issue 11 years ago • 9 comments

choptastic avatar Jun 15 '14 19:06 choptastic

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

davidw avatar Aug 04 '14 13:08 davidw

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.

choptastic avatar Aug 04 '14 16:08 choptastic

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.

davidw avatar Aug 05 '14 08:08 davidw

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" [email protected] 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.

choptastic avatar Aug 05 '14 14:08 choptastic

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...

davidw avatar Aug 05 '14 15:08 davidw

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()).

aramallo avatar Jul 09 '15 15:07 aramallo

Awesome! Thanks!

choptastic avatar Jul 09 '15 16:07 choptastic

Thanks to you! Awesome library :-)

On 9 Jul 2015, at 17:12, Jesse Gumm [email protected] wrote:

Awesome! Thanks!

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

aramallo avatar Jul 09 '15 16:07 aramallo

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.

erszcz avatar Aug 19 '16 12:08 erszcz