Skip to content

Commit

Permalink
Add GithubObject.last_modified_datetime to have last_modified as …
Browse files Browse the repository at this point in the history
…a `datetime` (#2772)
  • Loading branch information
chouetz committed Nov 26, 2023
1 parent c8b4fcb commit e7ce818
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions github/GithubObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,13 @@ def last_modified(self) -> Optional[str]:
"""
return self._headers.get(Consts.RES_LAST_MODIFIED) # type: ignore

@property
def last_modified_datetime(self) -> Optional[datetime]:
"""
:type: datetime
"""
return self._makeDatetimeAttribute(self.last_modified).value # type: ignore

def get__repr__(self, params: Dict[str, Any]) -> str:
"""
Converts the object to a nicely printable string.
Expand Down
6 changes: 5 additions & 1 deletion tests/GithubObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import unittest
from datetime import datetime, timedelta, timezone

from dateutil.tz.tz import tzoffset
from dateutil.tz.tz import tzoffset, tzutc

from . import Framework

Expand Down Expand Up @@ -78,6 +78,10 @@ def testMakeDatetimeAttribute(self):
"2021-01-23T12:34:56.000-06:00",
datetime(2021, 1, 23, 12, 34, 56, tzinfo=tzoffset(None, -21600)),
),
(
"Mon, 11 Sep 2023 14:07:29 GMT",
datetime(2023, 9, 11, 14, 7, 29, tzinfo=tzutc()),
),
]:
actual = gho.GithubObject._makeDatetimeAttribute(value)
self.assertEqual(gho._ValuedAttribute, type(actual), value)
Expand Down

0 comments on commit e7ce818

Please sign in to comment.