[erlang-questions] [ANN] qdate - Unified Date Formatting/Parsing and Timezone Management
Tue Apr 30 08:50:01 CEST 2013
Have you also looked at tempo, https://github.com/selectel/tempo ?
Your library and tempo could probably be combined
On Apr 30, 2013, at 07:09 , Jesse Gumm wrote:
> Hello Erlangers,
> I'm proud to announce the beta release (v0.1.0) of "qdate" - a unified date parsing/formatting and timezone management utility for Erlang.
> Blog post describing my thoughts that went into its development
> Source code on GitHub (includes a README that covers all the functionality)
> At its core, qdate is basically a wrapper around ec_date (fork of dh_date and part of erlware_commons) and erlang_localtime.
> 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).
> Briefly, here's what it does:
> * 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:
> > qdate:to_string("Y-m-d g:ia", Date).
> "2012-12-21 5:51pm"
> > qdate:to_string(<<"Y-m-d g:ia">>, Date).
> <<"2012-12-21 5:51pm">>
> > qdate:to_unixtime(Date).
> > qdate:to_date(Date).
> > qdate:to_now(Date).
> % Note, that the argument `Date` can be anything
> % that's a Date/Time Format (datetime Tuple, now tuple,
> % Integer (unixtime), or string ("2012-12-21 5:51pm")
> * Extends ec_date's formatting functions to include PHP's timezone-related characters:
> > qdate:to_string("Y-m-d g:ia T", Date)
> "2012-12-21 5:51pm CST"
> * Able to pre-parse timezones from text strings, and convert from one timezone to another:
> % Read Timezone from string, convert to datetime in EST
> > qdate:to_date("2012-12-21 5:51pm CST","EST").
> % Read timezone from string, convert to a string in EST
> > qdate:to_string("n/j/Y g:ia T","2012-12-21 5:51pm CST", "EST").
> "12/21/2012 6:51pm EST"
> * Register timezones with the qdate server by a key (to make a timezone alias) or by pid():
> %% Set timezone for the current process to GMT
> > qdate:set_timezone("GMT").
> %% Set timezone for some_key to HKT
> > qdate:set_timezone(some_key, "HKT").
> * Register custom formatting strings with the qdate server, for quick reference.
> > qdate:register_format(long_date, "l, F jS, Y g:i A T").
> > qdate:to_string(long_date,1356133860).
> "Friday, December 21st, 2012 11:51 PM GMT"
> * Register custom parsing functions with the qdate server, to be transparently used for conversion.
> > qdate:register_parser(weird_format, fun parse_esoteric_format/1).
> > qdate:to_date("20121221.115100").
> * Attempt to maintain API compatibility with ec_date by supporting qdate:parse, qdate:nparse, and qdate:format.
> I hope some of you find this useful in your apps.
> 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.
> Thanks, and I hope everyone has a glorious day or evening or whatever timezone you happen to be in.
> Jesse Gumm
> Owner, Sigma Star Systems
> 414.940.4866 || sigma-star.com || @jessegumm
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions