Modify ↓
Opened 18 months ago
Closed 18 months ago
#13604 closed defect (fixed)
Python 3.12.0b1: datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version
Reported by: | Jun Omae | Owned by: | Jun Omae |
---|---|---|---|
Priority: | normal | Milestone: | 1.6 |
Component: | general | Version: | |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: |
Adapt to |
||
API Changes: | |||
Internal Changes: |
Description
The following is warned on calling parse_date
with Python 3.12.
trac/util/datefmt.py:646: DeprecationWarning: datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.fromtimestamp(timestamp, datetime.UTC). datetime.utcfromtimestamp(ts)
Patch:
-
trac/util/datefmt.py
diff --git a/trac/util/datefmt.py b/trac/util/datefmt.py index 80b574feb..d407b86ba 100644
a b def parse_date(text, tzinfo=None, locale=None, hint='date'): 639 639 date=text, hint=formatted_hint, isohint=isohint) 640 640 raise TracError(msg, _('Invalid Date')) 641 641 # Make sure we can convert it to a timestamp and back - 642 # utcfromtimestamp() may raise OverflowError and OSError if out of642 # fromtimestamp(..., utc) may raise OverflowError and OSError if out of 643 643 # range by platform C gmtime() and gmtime() failure 644 644 ts = to_timestamp(dt) 645 645 try: 646 datetime. utcfromtimestamp(ts)646 datetime.fromtimestamp(ts, utc) 647 647 except (ValueError, OverflowError, OSError): 648 648 raise TracError(_('The date "%(date)s" is outside valid range. ' 649 649 'Try a date closer to present time.', date=text),
Attachments (0)
Change History (1)
comment:1 by , 18 months ago
Release Notes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
Fixed in [17707].