Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated utcnow() with now() #867

Merged
merged 1 commit into from
Mar 28, 2024

Conversation

argilo
Copy link
Contributor

@argilo argilo commented Mar 27, 2024

As of Python 3.12, datetime.utcnow() is deprecated, with the recommended replacement being datetime.now(timezone.utc). I made that replacement here. This was a simple search-and-replace, except in listener_nmea_crlf.py where I modified the code to be more like the other scripts. So far I haven't done much testing apart from firing up auto_rx.

@@ -417,7 +417,7 @@ def process_directory(log_dir, output_dir, status_file, time_limit = 60):


# Calculate the age of the last data point in minutes.
_data_age = (pytz.utc.localize(datetime.datetime.utcnow()) - parse(last_time)).total_seconds() / 60.0
_data_age = (pytz.utc.localize(datetime.datetime.now(datetime.timezone.utc)) - parse(last_time)).total_seconds() / 60.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need the pytz.utc.localize( ) call removed, as that expects a naive datetime object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed.

@@ -969,7 +969,7 @@ def sonde_search(self, first_only=False):
(_freq_decimate, _power_decimate) = peak_decimation(freq / 1e6, power, 10)
scan_result["freq"] = list(_freq_decimate)
scan_result["power"] = list(_power_decimate)
scan_result["timestamp"] = datetime.datetime.utcnow().isoformat()
scan_result["timestamp"] = datetime.datetime.now(datetime.timezone.utc).isoformat()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that this is going to change behaviour:

>>> datetime.datetime.utcnow().isoformat()
'2024-03-27T22:36:59.792134'
>>> datetime.datetime.now(datetime.timezone.utc).isoformat()
'2024-03-27T22:37:09.889948+00:00'

Maybe it should get a more specific time format?

@darksidelemm darksidelemm merged commit 51745e7 into projecthorus:testing Mar 28, 2024
1 check passed
@argilo argilo deleted the replace-utcnow branch March 29, 2024 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants