Dan Buch is sharing code with you

Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.

Don't show this again

meatballhat / Dt63

Python datetime object string (en|de)coder

Clone this repository (size: 32.9 KB): HTTPS / SSH
hg clone https://bitbucket.org/meatballhat/dt63
hg clone ssh://hg@bitbucket.org/meatballhat/dt63

Dt63 overview

Recent commits See more »

Author Revision Comments Message Labels Date
Dan Buch 008b9fa4dad7 using sdist to build paver-minilib.py and setup.py, ignoring egg-info files
convert-repo e857f9b7e8ab update tags
Dan Buch bac8f13e8634 added README with doctests, test runner for doctests
Dan Buch 15c36e09836a added integration test and minimal unit test, updated metadata, added interface with 'codecs' and registered encoder and decoder
Tag
0.2.0
Dan Buch a4a15bbb0a7d added publish command
How to use Dt63
===============
The Dt63 encoder will accept either datetime objects or ISO-formatted time
strings, returning an ascii hash::

        >>> from datetime import datetime
        
        >>> import dt63

        >>> mydate = datetime(1996, 10, 5, 11, 44, 27, 73762)
        
        >>> mydate_str = str(mydate)
        
        >>> print mydate_str
        1996-10-05 11:44:27.073762
        
        >>> from_obj = dt63.encode(mydate)
        
        >>> from_str = dt63.encode(mydate_str)
        
        >>> assert from_obj == from_str
        
        >>> print from_obj, from_str
        J96A5BiR073762 J96A5BiR073762

The Dt63 encoder and decoder are registered
with the standard library codecs on import and may be used during str.encode
and str.decode calls::

        >>> datestr = str(datetime(2001, 8, 9, 12, 13, 33, 88321))
        
        >>> print datestr
        2001-08-09 12:13:33.088321
        
        >>> encdate = datestr.encode('dt63')
        
        >>> print encdate
        K0189CDX088321
        
        >>> assert encdate.decode('dt63') == datestr


What's the point?
+++++++++++++++++
I needed a way to retain fine-grained date information in some sort of id
which could be passed in http GET requests.  Yes, I'm sure there are a 
bajillion simpler ways to do this, but I felt like solving the problem
this way.
        
.. vim:filetype=rst