Erlang - How Can I Parse RFC1123 Dates to Erlang?

Without using a third-party module, what steps do I need to take to convert this:

<<"Mon, 17 Feb 2014 11:07:53 GMT">>

In that?:

[17, 2, 2014, 10, 07, 53]

Most of the answers I offer Google use a library. Until now, I suspect that I’ll get somewhere according to a template corresponding to a formatted date string.

Sort of:

<<_:5/binary, Date:2/binary>> = <<"Mon, 17 Feb 2014 11:07:53 GMT">>...

I think this should lead to the following “coincidence”

Date = 17...

This is based on the idea found here - https://groups.google.com/forum/#!topic/erlang-programming/OpXSqt3U86c - Is this a good approach?

Is there any BIF or modules that can help with this? And besides, how do I convert / display "Feb" to an integer?

+1
4

:

1> <<_:5/binary, Date:2/binary>> = <<"Mon, 17 Feb 2014 11:07:53 GMT">>.
** exception error: no match of right hand side value <<"Mon, 17 Feb 2014 11:07:53 GMT">>

, :

2> <<_:5/binary, Date:2/binary, Rest/binary>> = <<"Mon, 17 Feb 2014 11:07:53 GMT">>.
<<"Mon, 17 Feb 2014 11:07:53 GMT">>
3> Date.
<<"17">>

, Date , ASCII- 1 7. binary_to_integer:

4> binary_to_integer(Date).
17

, - :

month_name_to_integer("Jan") -> 1;
month_name_to_integer("Feb") -> 2;
...
month_name_to_integer("Dec") -> 12.
+2
+2
Bin = <<"Mon, 17 Feb 2014 11:07:53 GMT">>,
L = binary_to_list(Bin),
{match, Res} = 
    re:run(L, "[0-9]+", [global, {capture, all, list}]),
[list_to_integer(X) || [X] <- Res].

:

[17,2014,11,7,53]
+1

? ?

erlware_commons

ec_date:parse("Mon, 17 Feb 2014 11:07:53 GMT").

+1

Source: https://habr.com/ru/post/1659963/


All Articles