[erlang-questions] parsing dates

144 views
Skip to first unread message

Joel Reymont

unread,
Dec 14, 2011, 4:18:41 PM12/14/11
to erlang-q...@erlang.org
Is there a function somewhere to parse a date like this:

2008-06-30T00:00:00.000Z

Thanks, Joel

---
Hardcore embedded Linux development
http://www.linkedin.com/in/joelreymont
Device drivers, firmware and debugging


_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

Steve Strong

unread,
Dec 14, 2011, 4:20:48 PM12/14/11
to Joel Reymont, erlang-q...@erlang.org
I use something like:

    <<Year:4/binary,"-",
      Month:2/binary,"-",
      Day:2/binary,"T",
      Hour:2/binary,":",
      Minute:2/binary,":",
      Second:2/binary,
      _Rem/binary>> = list_to_binary(Date)

from there, it's trivial to return a datetime() tuple.

Cheers,

Steve

-- 
Steve Strong
@srstrong

Sent with Sparrow

Anders Nygren

unread,
Dec 14, 2011, 5:08:36 PM12/14/11
to Joel Reymont, erlang-q...@erlang.org
Is this to primitive?

> Date="2008-06-30T00:00:00.000Z".
"2008-06-30T00:00:00.000Z"
> io_lib:fread("~d-~d-~dT~d:~d:~d.~dZ",Date).
{ok,[2008,6,30,0,0,0,0],[]}

/Anders

Wei

unread,
Dec 15, 2011, 3:18:03 AM12/15/11
to erlang-q...@erlang.org
see jlib:datetime_string_to_timestamp/1 in ejabberd

On Dec 15, 5:18 am, Joel Reymont <joe...@gmail.com> wrote:
> Is there a function somewhere to parse a date like this:
>
> 2008-06-30T00:00:00.000Z
>
>     Thanks, Joel
>
> ---

> Hardcore embedded Linux developmenthttp://www.linkedin.com/in/joelreymont


> Device drivers, firmware and debugging
>
> _______________________________________________
> erlang-questions mailing list

> erlang-questi...@erlang.orghttp://erlang.org/mailman/listinfo/erlang-questions

Gordon Guthrie

unread,
Dec 15, 2011, 5:01:40 AM12/15/11
to Joel Reymont, erlang-q...@erlang.org
Dale Harvey's dh_date module does a lot of date parsing and formatting:
https://github.com/daleharvey/dh_date

Gordon

--
Gordon Guthrie
CEO hypernumbers

http://hypernumbers.com
t: hypernumbers
+44 7776 251669

Jesse Gumm

unread,
Dec 15, 2011, 7:15:36 AM12/15/11
to Gordon Guthrie, erlang-q...@erlang.org

Write, I did not know about this. I had my own little homegrown date parser, but this is way more comprehensive. Very cool, thank you.

-Jesse

--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866
www.sigma-star.com
@jessegumm

Jesse Gumm

unread,
Dec 15, 2011, 7:17:23 AM12/15/11
to Gordon Guthrie, erlang-q...@erlang.org

Wow at the auto correct fail there. First word should have been "Wow", not "write".

--
Jesse Gumm
Owner, Sigma Star Systems
414.940.4866
www.sigma-star.com
@jessegumm

Gordon Guthrie

unread,
Dec 15, 2011, 7:22:07 AM12/15/11
to Jesse Gumm, erlang-q...@erlang.org
Yeah, his aim was to make a standard module like the corresponding PHP
library that could handle the RFC date formats in HTTP and stuff...

Its a nice sweet little library - should be a standard library really, I think.

Gordon

Eric B Merritt

unread,
Dec 15, 2011, 9:53:30 AM12/15/11
to Gordon Guthrie, erlang-q...@erlang.org, Jesse Gumm
With Dale's concent and approval, I made some parsing and testing
improvements and moved this into erlware_commons (whose point is to be
an extension to the stdlib) it is here ->
https://github.com/erlware/erlware_commons/blob/master/src/ec_date.erl

Andrew Thompson

unread,
Dec 15, 2011, 12:42:00 PM12/15/11
to erlang-q...@erlang.org
On Thu, Dec 15, 2011 at 09:53:30AM -0500, Eric B Merritt wrote:
> With Dale's concent and approval, I made some parsing and testing
> improvements and moved this into erlware_commons (whose point is to be
> an extension to the stdlib) it is here ->
> https://github.com/erlware/erlware_commons/blob/master/src/ec_date.erl

So I can't list it as a rebar dep anymore without pulling down a whole
bunch of extraneous code, or maintaining my own fork of dh_date?

Also, why does the README for erlware commons talk about some expert
system stuff, if its supposed to be an 'extension to the erlang stdlib'?

Andrew

Jesse Gumm

unread,
Dec 16, 2011, 3:18:38 PM12/16/11
to erlang-q...@erlang.org
Sure you can, the existence of ec_date doesn't negate the existence of
dh_date. If you want all the spiffy changes in ec_date without
pulling all of the ec libraries, you can always do a patch and submit
a pull request to Dale and see what happens there.

-Jesse

> So I can't list it as a rebar dep anymore without pulling down a whole
> bunch of extraneous code, or maintaining my own fork of dh_date?


--
Jesse Gumm
Sigma Star Systems
414.940.4866
gu...@sigma-star.com
http://www.sigma-star.com

Dale Harvey

unread,
Dec 16, 2011, 6:24:51 PM12/16/11
to Jesse Gumm, erlang-q...@erlang.org
Sorry missed this

Yeh I sent a message to Eric to see if those patched to ec_date could go back upstream for people who arent using the full commons library, if anyone else wants to do that Ill be happy to merge, I may try if I get some time.

I just wanted to mention I dont think this belongs in otp, I do however thing it should be a

$ magic-erlang-package-manager-distributed-with-erlang install dh_date

away though :)

Cheers
Dale
Reply all
Reply to author
Forward
0 new messages