Mercurial > p > roundup > code
comparison roundup/anypy/datetime_.py @ 7589:6894f152d49a
fix: issue2551278 - datetime.datetime.utcnow deprecation.
Original fix always failed the import and fell back to the exception case.
This method should work and test both code paths in datetime_.py.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Wed, 26 Jul 2023 23:59:35 -0400 |
| parents | 8f29e4ea05ce |
| children | d5d7ecd31864 |
comparison
equal
deleted
inserted
replaced
| 7588:8329b2227adb | 7589:6894f152d49a |
|---|---|
| 1 # https://issues.roundup-tracker.org/issue2551278 | 1 # https://issues.roundup-tracker.org/issue2551278 |
| 2 # datetime.utcnow deprecated | 2 # datetime.utcnow deprecated |
| 3 try: | 3 try: |
| 4 from datetime import now, UTC | 4 from datetime import datetime, UTC |
| 5 | 5 |
| 6 def utcnow(): | 6 def utcnow(): |
| 7 return now(UTC) | 7 return datetime.now(UTC) |
| 8 | |
| 8 except ImportError: | 9 except ImportError: |
| 9 import datetime | 10 from datetime import datetime |
| 10 | 11 |
| 11 def utcnow(): | 12 def utcnow(): |
| 12 return datetime.datetime.utcnow() | 13 return datetime.utcnow() |
