[erlang-questions] [ANN] qdate - Unified Date Formatting/Parsing and Timezone Management
Tue Apr 30 21:57:48 CEST 2013
Enh, I would tend to prefer Jesse’s qdate because it is pure Erlang.
From: [mailto:] On Behalf Of Dmitrii Dimandt
Sent: Tuesday, April 30, 2013 01:50
To: Jesse Gumm
Cc: Erlang Questions
Subject: Re: [erlang-questions] [ANN] qdate - Unified Date Formatting/Parsing and Timezone Management
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:
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).
> qdate:to_string(<<"Y-m-d g:ia">>, 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
%% 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").
"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).
* 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.
Owner, Sigma Star Systems
414.940.4866 || sigma-star.com <http://sigma-star.com/> || @jessegumm
erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions