Skip to content

Commit

Permalink
Handle additional datetime deprecations
Browse files Browse the repository at this point in the history
- Remove deprecated utcfromtimestamp()
- Feed timezone-aware datetime to utcttimetuple() to avoid
unexpected results
  • Loading branch information
tw4l committed Oct 28, 2024
1 parent 0f475a5 commit 3d720dd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions warcio/timeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ def timestamp_to_sec(string):
1420070399
"""

return calendar.timegm(timestamp_to_datetime(string).utctimetuple())
dt = timestamp_to_datetime(string, tzinfo=timezone.utc)
return calendar.timegm(dt.utctimetuple())


def sec_to_timestamp(secs):
Expand All @@ -366,7 +367,7 @@ def sec_to_timestamp(secs):
'20141231235959'
"""

return datetime_to_timestamp(datetime.utcfromtimestamp(secs))
return datetime_to_timestamp(datetime.fromtimestamp(secs, timezone.utc))


def timestamp_to_http_date(string):
Expand Down

0 comments on commit 3d720dd

Please sign in to comment.