<div dir="ltr">Hello Erlangers,<div><br></div><div>I'm proud to announce the beta release (v0.1.0) of "qdate" - a unified date parsing/formatting and timezone management utility for Erlang.</div><div><br></div>
<div>Blog post describing my thoughts that went into its development</div><div><a href="http://sigma-star.com/blog/post/qdate" target="_blank">http://sigma-star.com/blog/post/qdate</a><br></div><div><br></div><div>Source code on GitHub (includes a README that covers all the functionality)</div>
<div><a href="https://github.com/choptastic/qdate" target="_blank">https://github.com/choptastic/qdate</a></div>
<div><br></div><div><br></div><div>At its core, qdate is basically a wrapper around ec_date (fork of dh_date and part of erlware_commons) and erlang_localtime.</div>
<div><br></div><div>But it's much more than just a wrapper. It's the complete date and time utility I feel is greatly needed in the Erlang world (since I found myself needing it).</div><div><br></div>
<div>Briefly, here's what it does:</div><div><br></div><div>* Easily convert from any date format to any other date format: datetime(), now(), unix timestamp, and formatted date strings (list and binaries) are all acceptable:</div>
<div><font face="courier new, monospace"> > qdate:to_string("Y-m-d g:ia", Date).</font></div><div><font face="courier new, monospace"> "2012-12-21 5:51pm"</font></div><div><font face="courier new, monospace"> > qdate:to_string(<<"Y-m-d g:ia">>, Date).</font></div>
<div><font face="courier new, monospace"> <<"2012-12-21 5:51pm">></font></div><div><font face="courier new, monospace"> > qdate:to_unixtime(Date).</font></div><div><font face="courier new, monospace"> 1356112260</font></div>
<div><font face="courier new, monospace"> > qdate:to_date(Date).</font></div><div><font face="courier new, monospace"> {{2012,12,21},{17,51,0}}</font></div><div><font face="courier new, monospace"> > qdate:to_now(Date).</font></div>
<div><font face="courier new, monospace"> {1356,112260,0}</font></div><div><font face="courier new, monospace"> % Note, that the argument `Date` can be anything </font></div><div><font face="courier new, monospace"> % that's a Date/Time Format (datetime Tuple, now tuple,</font></div>
<div><font face="courier new, monospace"> % Integer (unixtime), or string ("2012-12-21 5:51pm")</font></div><div><br></div>
<div>* Extends ec_date's formatting functions to include PHP's timezone-related characters:</div><div><font face="courier new, monospace"> > qdate:to_string("Y-m-d g:ia T", Date)</font></div>
<div><font face="courier new, monospace"> "2012-12-21 5:51pm CST"</font></div><div><br></div><div>* Able to pre-parse timezones from text strings, and convert from one timezone to another:</div><div style>
<font face="courier new, monospace"> % Read Timezone from string, convert to datetime in</font><span style="font-family:'courier new',monospace"> EST</span></div><div><font face="courier new, monospace"> > qdate:to_date("2012-12-21 5:51pm CST","EST").</font></div>
<div><font face="courier new, monospace"> {{2012,12,21},{18,51,0}}</font></div><div><font face="courier new, monospace"> % Read timezone from string, convert to a string in EST</font></div><div><font face="courier new, monospace"> > qdate:to_string("n/j/Y g:ia T","2012-12-21 5:51pm CST", "EST").</font></div>
<div><font face="courier new, monospace"> "12/21/2012 6:51pm EST"</font></div><div><br></div>
<div>* Register timezones with the qdate server by a key (to make a timezone alias) or by pid():</div><div><font face="courier new, monospace"> %% Set timezone for the current process to GMT</font></div><div>
<font face="courier new, monospace"> > qdate:set_timezone("GMT").</font></div><div><font face="courier new, monospace"> %% Set timezone for some_key to HKT</font></div><div><font face="courier new, monospace"> > qdate:set_timezone(some_key, "HKT").</font></div>
<div><font face="courier new, monospace"><br></font></div><div>* Register custom formatting strings with the qdate server, for quick reference.</div><div>
<font face="courier new, monospace"> > qdate:register_format(long_date, "l, F jS, Y g:i A T").<br></font></div><div><font face="courier new, monospace"> ok</font></div><div><font face="courier new, monospace"> > qdate:to_string(long_date,1356133860).</font></div>
<div><font face="courier new, monospace"> "Friday, December 21st, 2012 11:51 PM GMT"</font></div><div><font face="courier new, monospace"><br></font></div><div>* Register custom parsing functions with the qdate server, to be transparently used for conversion.<br>
</div><div><font face="courier new, monospace"> > qdate:register_parser(weird_format, fun parse_esoteric_format/1).</font></div><div><font face="courier new, monospace"> ok</font></div><div><font face="courier new, monospace"> > qdate:to_date("20121221.115100").</font></div>
<div><font face="courier new, monospace"> {{2012,12,21},{11,51,00}}</font></div><div><br></div>
<div>* Attempt to maintain API compatibility with ec_date by supporting qdate:parse, qdate:nparse, and qdate:format.</div><div><br></div><div><br></div><div>I hope some of you find this useful in your apps.</div><div><br>
</div><div style>Any issues, comments, complaints, bug reports, whatever, feel free to post in this thread, make a github issue, shoot me a message on twitter (@jessegumm) or email me directly.</div><div style><br></div>
<div style>
Thanks, and I hope everyone has a glorious day or evening or whatever timezone you happen to be in.</div><div><br></div><div><div>-- <br>Jesse Gumm<br>Owner, Sigma Star Systems<br>
<a href="tel:414.940.4866" value="+14149404866" target="_blank">414.940.4866</a> || <a href="http://sigma-star.com" target="_blank">sigma-star.com</a> || @jessegumm
</div></div></div>