Skip to content

Commit

Permalink
replace deprecated utcnow
Browse files Browse the repository at this point in the history
  • Loading branch information
branchvincent committed Dec 2, 2024
1 parent 8c471c3 commit 8288086
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
9 changes: 1 addition & 8 deletions boltons/ecoutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,7 @@
RLIMIT_FDS_SOFT, RLIMIT_FDS_HARD = 0, 0


def _get_utc_now():
try:
return datetime.datetime.utcnow()
except Exception:
return datetime.datetime.now(datetime.timezone.utc)


START_TIME_INFO = {'time_utc': str(_get_utc_now()),
START_TIME_INFO = {'time_utc': str(datetime.datetime.now(datetime.timezone.utc)),
'time_utc_offset': -time.timezone / 3600.0}


Expand Down
10 changes: 5 additions & 5 deletions boltons/timeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ def isoparse(iso_str):
"""Parses the limited subset of `ISO8601-formatted time`_ strings as
returned by :meth:`datetime.datetime.isoformat`.
>>> epoch_dt = datetime.utcfromtimestamp(0)
>>> epoch_dt = datetime.fromtimestamp(0, timezone.utc).replace(tzinfo=None)
>>> iso_str = epoch_dt.isoformat()
>>> print(iso_str)
1970-01-01T00:00:00
>>> isoparse(iso_str)
datetime.datetime(1970, 1, 1, 0, 0)
>>> utcnow = datetime.utcnow()
>>> utcnow = datetime.now(timezone.utc).replace(tzinfo=None)
>>> utcnow == isoparse(utcnow.isoformat())
True
Expand Down Expand Up @@ -213,7 +213,7 @@ def decimal_relative_time(d, other=None, ndigits=0, cardinalize=True):
localization into other languages and custom phrasing and
formatting.
>>> now = datetime.utcnow()
>>> now = datetime.now(timezone.utc).replace(tzinfo=None)
>>> decimal_relative_time(now - timedelta(days=1, seconds=3600), now)
(1.0, 'day')
>>> decimal_relative_time(now - timedelta(seconds=0.002), now, ndigits=5)
Expand All @@ -223,7 +223,7 @@ def decimal_relative_time(d, other=None, ndigits=0, cardinalize=True):
"""
if other is None:
other = datetime.utcnow()
other = datetime.now(timezone.utc).replace(tzinfo=None)
diff = other - d
diff_seconds = timedelta.total_seconds(diff)
abs_diff = abs(diff)
Expand Down Expand Up @@ -252,7 +252,7 @@ def relative_time(d, other=None, ndigits=0):
Returns:
A short English-language string.
>>> now = datetime.utcnow()
>>> now = datetime.now(timezone.utc).replace(tzinfo=None)
>>> relative_time(now, ndigits=1)
'0 seconds ago'
>>> relative_time(now - timedelta(days=1, seconds=36000), ndigits=1)
Expand Down

0 comments on commit 8288086

Please sign in to comment.