Skip to content

rfc1123 issues #270

Open
Open

Description

@trancee

I am using pendulum==2.0.3 and I want to return an RFC-1123 compliant date in the HTTP response headers as defined here:
HTTP-date

The date is formatted like this (today's date):
Mon, 27 Aug 2018 02:13:09 +0000

Now I will feed that date back into my code and Pendulum should parse it, but instead throws an exception:

pendulum.parsing.exceptions.ParserError: Unable to parse string [Mon, 27 Aug 2018 02:13:09 +0000]

According to the documentation which I shared the link above, the date should be formatted something like this:

Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123

How come Pendulum produces a date format which it can't parse itself?
And is there proper support for RFC 1123 and RFC 822 in Pendulum or do I need to use something else?

Thanks for your help and guidance.

Activity

  1. sdispater commented on Aug 28, 2018

    @sdispater
    Collaborator

    You can take two approaches here. You can either use the from_format() helper:

    >>> import pendulum
    >>> pendulum.from_format("Mon, 27 Aug 2018 02:13:09 +0000", "ddd, DD MMM YYYY HH:mm:ss ZZ")
    DateTime(2018, 8, 27, 2, 13, 9, tzinfo=Timezone('+00:00'))

    or use the parse() method in non-strict mode:

    >>> import pendulum
    >>> pendulum.parse("Mon, 27 Aug 2018 02:13:09 +0000", strict=False)
    DateTime(2018, 8, 27, 2, 13, 9, tzinfo=Timezone('+00:00'))
  2. trancee commented on Aug 29, 2018

    @trancee
    Author

    Thank you for the tips. I chose the second approach and that seems to be working.

    But for my first question, I am still not sure. The referred specification about HTTP-date says that the timezone should be GMT whereas Pendulum returns +0000.

    Mon, 27 Aug 2018 02:13:09 +0000

    Is it possible that Pendulumn returns GMT in place of +0000 to be compliant with the standards of rfc1123-date and rfc850-date?

  3. sdispater commented on Sep 24, 2018

    @sdispater
    Collaborator

    From what I read in the RFC it says:

    There is a strong trend towards the use of numeric timezone
    indicators, and implementations SHOULD use numeric timezones
    instead of timezone names. However, all implementations MUST
    accept either notation. If timezone names are used, they MUST
    be exactly as defined in RFC-822.

    So what Pendulum is doing is correct and the recommended way.

  4. trancee commented on Sep 24, 2018

    @trancee
    Author

    I did not say Pendulum is wrong, and I agree with the above quoted citation. But still, for rfc1123 and rfc850 dates it should not be numerical but fixed GMT instead of +0000.

    Currently, I simply replace it manually after I converted the date with Pendulum, but it would be nice if Pendulum would do it according to rfc1123 and rfc850 by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions