[erlang-questions] [ANN] qdate - Unified Date Formatting/Parsing and Timezone Management

51 views
Skip to first unread message

Jesse Gumm

unread,
Apr 30, 2013, 1:09:50 AM4/30/13
to Erlang Questions
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).
    1356112260
    > qdate:to_date(Date).
    {{2012,12,21},{17,51,0}}
    > qdate:to_now(Date).
    {1356,112260,0}
    % 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").
   {{2012,12,21},{18,51,0}}
   % 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").
    ok
    > 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).
     ok
     > qdate:to_date("20121221.115100").
     {{2012,12,21},{11,51,00}}

* 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

Dmitrii Dimandt

unread,
Apr 30, 2013, 2:50:01 AM4/30/13
to Jesse Gumm, Erlang Questions
Have you also looked at tempo, https://github.com/selectel/tempo ?

Your library and tempo could probably be combined

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

Jesse Gumm

unread,
Apr 30, 2013, 12:45:08 PM4/30/13
to Dmitrii Dimandt, Erlang Questions

Hi Dmitrii,

I had not looked into tempo (I was not aware of its existence). Given that qdate is fundamentally a wrapper, I could see adding an option to change formatting backend to tempo (qdate currently uses ec_date as the backend for both parsing and formatting).

Thank you, I appreciate the suggestion,

-Jesse

David Mercer

unread,
Apr 30, 2013, 3:57:48 PM4/30/13
to Dmitrii Dimandt, Jesse Gumm, Erlang Questions

Enh, I would tend to prefer Jesse’s qdate because it is pure Erlang.

 

Cheers,

 

DBM

Reply all
Reply to author
Forward
0 new messages