brandon-rhodes / pyephem

Scientific-grade astronomy routines for Python
Other
783 stars 121 forks source link

Python 3.12 datetime.utcnow() deprecation #264

Closed aaronwmorris closed 1 year ago

aaronwmorris commented 1 year ago

With the deprecation of datetime.utcnow(), what is the proper way of passing dates to pyephem?

https://github.com/brandon-rhodes/pyephem/blob/master/ephem/doc/date.rst still shows the utcnow() method. Python's suggested code is to use datetime.now(timezone.utc) but this produces a timezone aware object where utcnow() produces a timezone naive object. Will the timezone aware object cause any problems with pyephem?

brandon-rhodes commented 1 year ago

With the deprecation of datetime.utcnow(), what is the proper way of passing dates to pyephem?

Unless Python removes utcnow() entirely, my guess is that I keep the documentation as it is now. The advice to use utcnow() was added to the docs in 2015 and I don't recall having many user problems as a result? So unless it starts causing new problems for people, I think the advice will be kept the same.

Will the timezone aware object cause any problems with pyephem?

Happily, they are fully supported — check out the documentation here for an example:

https://rhodesmill.org/pyephem/quick.html#from-a-specific-timezone

aaronwmorris commented 1 year ago

The release notes for Python 3.12 indicate utcnow() will be removed from a future release (it does not mention a specific release like some of the other deprecations). Using utcnow in Python 3.12 results in a deprecation warning.

Quoted from https://docs.python.org/3/whatsnew/3.12.html

datetime: datetime.datetime’s utcnow() and utcfromtimestamp() are deprecated and will be removed in a future version. Instead, use timezone-aware objects to represent datetimes in UTC: respectively, call now() and fromtimestamp() with the tz parameter set to datetime.UTC. (Contributed by Paul Ganssle in gh-103857.)