[Baypiggies] HTTP date format

Fahrzin Hemmati fahhem at google.com
Wed Feb 17 17:19:54 EST 2016


Sorry to be 'that guy', but what is wrong with email.utils.formatdate? The
docs even mention HTTP for why usegmt is there.

On Wed, Feb 17, 2016 at 1:28 PM, Ian Zimmerman <itz at buug.org> wrote:

> On 2016-02-17 20:58 +0000, Alex Young wrote:
>
> > datetime(1994, 11, 6, 8, 49, 37, 0, GMT()).strftime('%a, %d %b %Y
> %H:%M:%S
> > %Z')
>
> Same trouble as always: I ask a question after thinking hard about a
> problem and seeing the difficulties, and I assume others see the
> difficulties as well :-(
>
> Here, the main difficulty (the one which made me stop hacking and ask)
> is that strftime is locale dependent, while the RFC demands fixed
> English spelling.
>
> In the meantime I came up with this pearl:
>
> def rfc7231_of_timestamp(timestamp):
>     real_loc = locale.getlocale(locale.LC_ALL)
>     locale.setlocale(locale.LC_ALL, 'C')
>     try:
>         gmtuple = time.gmtime(timestamp)
>         return time.strftime('%a, %d %b %Y %H:%M:%S', gmtuple) + ' GMT'
>     finally:
>         locale.setlocale(locale.LC_ALL, real_loc)
>
> Do you think it has a chance in hell of working?  Note: portability to
> Windows is not important, portability to MacOS only mildly interesting.
>
> --
> Please *no* private copies of mailing list or newsgroup messages.
> Rule 420: All persons more than eight miles high to leave the court.
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> https://mail.python.org/mailman/listinfo/baypiggies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20160217/19b1526f/attachment-0001.html>


More information about the Baypiggies mailing list