Skip to content

GitPython parses RFC 2822 dates with timezone incorrectly #1247

Open
@yanniszark

Description

@yanniszark

Bug Report

Description

The parse_date function returns a wrong result, when using an RFC 2822 date with timezone.

In [24]: parse_date('Thu, 20 May 2021 13:38:44 +0300')
Out[24]: (1621517924, -10800)

This output is wrong.
1621517924 is supposed to be UTC time (10:38:44).
But instead, it is my time (13:38:44)

Source Code Investigation

The function calls are as following:

  1. repo.index.commit takes author_date as input, which is an RFC 2822 string.
  2. repo.index.commit calls Commit.create_from_tree with author_date.
  3. Commit.create_from_tree calls parse_date(author_date) to parse the date into author_time and author_offset.
  4. Commit.create_from_treecalls cls (aka Commit.__init__) passing author_time and author_offset.
  5. Commit.__init__ saves author_time and author_offset in authored_date and author_tz_offset.

Thus, the fault should lie with the parse_date function.

Environment

Tried with versions 2.1.11 and 3.1.14.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions