Welcome, guest | Sign In | My Account | Store | Cart

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).

Python, 9 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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 ( ) )
    

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.