ASPN ActiveState Programmer Network  
ActiveState, a division of Sophos
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups
Submit Recipe
My Recipes

All Recipes
All Cookbooks


View by Category

Title: Date & time RFC822 formatted for RSS2, etc (straw man)
Submitter: Bill Bell (other recipes)
Last Updated: 2008/05/07
Version no: 1.0
Category: Algorithms

 

Not Rated yet


Description:

I live in a geographical area whose daylight savings time provisions seem to fool software. I would therefore like to avoid mentioning time zone when I create a timestamp in RFC822 format. I have looked for but could not find an elegant way of expressing what I want. In hopes that someone will see this and be aghast at my ignorance, then provide something nice, I humbly offer the following.

It takes a datetime and gives back an RFC822 timestamp (I think).

Source: Text Source

def timeAsrfc822 ( theTime ) :

    import rfc822
    return rfc822 . formatdate ( rfc822 . mktime_tz ( rfc822 . parsedate_tz ( theTime . strftime ( "%a, %d %b %Y %H:%M:%S" ) ) ) )

if __name__ == "__main__" :

    import datetime
    print timeAsrfc822 ( datetime . datetime . now ( ) )

Discussion:

One of my teachers at university told me that (my code is cryptic enough that) I should work for IBM, and I think this proves him right. Anyway, the amount of manipulation needed to do something that seems so simple makes me suspicious. I'm also nervous about trusting systems that seem unable to keep the clock on my computer in sync with the national clock in Ottawa to do this. But probably the stuff that Python relies on differs from what makes the Windows thingy work.



Add comment

No comments.



Highest rated recipes:

1. A simple XML-RPC server

2. Web service accessible ...

3. Wrapping template engine ...

4. Assignment in expression

5. SOLVING THE METACLASS ...

6. Povray for python

7. Calling Windows API ...

8. Generic filter logic ...

9. Function Decorators by ...

10. MS SQL Server log monitor




Privacy Policy | Email Opt-out | Feedback | Syndication
© 2006 ActiveState Software Inc. All rights reserved.