parsing - Erlang - How Can I Parse RFC1123 Dates Into An Erlang Term? -


Without using third-party modules, what steps should I take to replace it:

 < Code> & lt; & Lt; "Mon, 17 February 2014 11:07:53 GMT" & gt; & Gt;   

In this:

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

Most of my It has been suggested to use one of the answers given by the library. Until now, I suspect that I can get somewhere with the pattern matching the formatted date string.

Something like this:

  & lt; _: 5 / binary, date: 2 / binary & gt; & Gt; = & Lt; & Lt; "Mon, 17 February 2014 11:07:53 GMT" & gt; & Gt; ...   

I think the following 'match' should be created

  date = 17 ...   

It is based on an idea found here - is this a good way?

Any BIF or module which can help with this? And apart from this, how do I convert "February" into an integer?

Let's try to open that:

  1> ; & Lt; & Lt; _: 5 / binary, date: 2 / binary & gt; & Gt; = & Lt; & Lt; "Mon, 17 February 2014 11:07:53 GMT" & gt; & Gt; ** Exception error: Any value on the right hand side & lt; & Lt; "Mon, 17 February 2014 11:07:53 GMT" & gt; & Gt;   

OK, we need to match the remaining binary at the same time:

  2> & Lt; & Lt; _: 5 / binary, date: 2 / binary, rest / binary & gt; & Gt; = & Lt; & Lt; "Mon, 17 February 2014 11:07:53 GMT" & gt; & Gt; & Lt; & Lt; "Mon, 17 February 2014 11:07:53 GMT" & gt; & Gt; 3 & gt; Date & Lt; & Lt; "17" & gt; & Gt;   

Now now date is a binary that contains ASCII digits 1 and 7 bytes. We will call that code to binary_to_integer :

  4> binary_to_integer (date).   

To convert months' names to an integer, the common way to do something like this is with the function:

  month_name_to_integer ("Jan") - & gt; 1; Month_name_to_integer ("Feb") - & gt; 2; ... month_name_to_enter ("Dec") - & gt; 12.    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -