Skip to content

Accept datetime instances as dates - #1050

Merged
Byron merged 2 commits into
gitpython-developers:masterfrom
mildsunrise:accept-datetime
Aug 31, 2020
Merged

Accept datetime instances as dates#1050
Byron merged 2 commits into
gitpython-developers:masterfrom
mildsunrise:accept-datetime

Conversation

@mildsunrise

Copy link
Copy Markdown
Contributor

There's no easy way to re-create a commit (i.e. for rewriting purposes), because dates must be formatted as strings, passed, then parsed back.

This patch allows parse_date() to accept datetime instances, such as those produced by from_timestamp().
Re-creating a commit is then possible:

Commit.create_from_tree(
repo=commit.repo,
tree=commit.tree,
message=commit.message,
parent_commits=commit.parents,
author=commit.author,
author_date=commit.authored_datetime,
committer=commit.committer,
commit_date=commit.committed_datetime,
)

There's no easy way to re-create a commit (i.e. for rewriting purposes), because dates must be formatted as strings, passed, then parsed back.
This patch allows parse_date() to accept datetime instances, such as those produced by from_timestamp() above.
@ByronByron added this to the v3.1.8 - Bugfixes milestone Aug 31, 2020
@Byron

Copy link
Copy Markdown
Member

Thanks a lot for your contribution.
It looks great 👍!

@Byron
Byron merged commit 98595da into gitpython-developers:masterAug 31, 2020
@mildsunrise
mildsunrise deleted the accept-datetime branch August 31, 2020 12:40
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@mildsunrise@Byron