Python Datetime -> RFC3339
Every time I need to convert a type to some other format Python makes me find a new library (poorly documented and not bi-directional). I know Python 3.x is slightly better about this. I can't wait to switch over.
Google Calendar API requires datetime to be in RFC3339 format. Python 2.x doesn't natively support formatting date times like this. Web articles didn't spell it out for me. An hour later I can now convert times back and forth. Without using libraries specific for this RFC you can get half way to your goal.
The RFC specifies date times that look like this: 2015-06-03T10:00:00.000-05:00
The -5:00 is the time zone offset or you can simply use the letter Z.
If you use the datetime library you can call somedatevar.isoformat('T')
and get most of what you need. You don't have the time zone but I'm guessing in most cases it is supplied by a user (web apps) or you can get it from the local machine with the timezone function.
This doesn't get you fancy error handling. It does work though for quick and dirty scripts. The other way can be achieved with datetime.strftime only in later versions of Python (3.x+). If you are on 2.x I suggest the dateutil library. Specifically the parser module. Good link explains it here: https://stackoverflow.com/questions/15577153/formatting-time-from-google-calendar-api-with-python
But wait... I thought you said you didn't want to find a library. I didn't but the dateutil library is helpful to do many conversions and not just for one specific time format. This seemed like the best of both worlds. I'm open to suggestions on how to do this even easier in an readable format. Could I use regular expressions? Sure, unfortunately a large portion of the world can't read them easily.
I'd like to point out Tumblr suggested RFC3339 is a popular tag. Part of me really hopes that a Tumblr GIF blog dedicated to formatting dates exists.








