New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GitPython parses RFC 2822 dates with timezone incorrectly #1247
Comments
|
Thanks for the report! The respective source is here, and I think it's very old too. I am also very sure that a lot of code depends on this behaviour so fixing it to match the docs will be a breaking change. Instead of that I propose to change the documentation instead. What do you think? |
|
Hi @Byron, Thanks a lot for the quick response!
I am using GitPython to make a commit and specify a date in RFC 2822 (date taken from another commit). Thus, when creating a commit with an RFC 2822 date, the resulting date is incorrect, it's not that the timezone has changed to balance the changed time.
I'm not sure about the |
|
To make my case more clear, here is a minimum reproducer: import os
import git
import tempfile
from pathlib import Path
from email import utils as email_utils
tmp_dir = tempfile.mkdtemp()
print("Repo folder: '%s'" % tmp_dir)
repo = git.Repo.init(tmp_dir)
Path(os.path.join(repo.working_dir, "example_file")).touch()
repo.index.add(["example_file"])
author = git.Actor("user", "user@example.com")
date = "Thu, 20 May 2021 13:38:44 +0300"
print("Input date: '%s'" % date)
repo.index.commit("Wrong date", author=author, committer=author,
author_date=date, commit_date=date)
print("Output date: '%s'" %
email_utils.format_datetime(repo.head.commit.authored_datetime))Which outputs: |
|
Thanks for making the issue easily reproducible. I have taken a look and noticed that the date in the commit arrives correctly, that's a pleasant surprise, and it can be expected that reading the same date both from the newly created commit (by re-reading it or by using the return value of My initial desire to not fix such a long-standing bug in fear of breakage makes the assumption that a lot of code depends on it. A way to find it would be to fix this issue and see how many new issues show up - in the worst case the release can be yanked to find another way of introducing a fix. Thanks a lot for your engagement here to help making this change, I do hope you would be willing to help fixing it too. Please note that if you do and no existing test breaks, it's desirable to add a new test for that. |
Bug Report
Description
The
parse_datefunction returns a wrong result, when using an RFC 2822 date with timezone.This output is wrong.
1621517924is 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:
repo.index.committakesauthor_dateas input, which is anRFC 2822string.repo.index.commitcallsCommit.create_from_treewithauthor_date.Commit.create_from_treecallsparse_date(author_date)to parse the date intoauthor_timeandauthor_offset.Commit.create_from_treecallscls(akaCommit.__init__) passingauthor_timeandauthor_offset.Commit.__init__savesauthor_timeandauthor_offsetinauthored_dateandauthor_tz_offset.Thus, the fault should lie with the
parse_datefunction.Environment
Tried with versions
2.1.11and3.1.14.The text was updated successfully, but these errors were encountered: