From 5262d58a0b97a04bbc3bd07a1c46c4a6a564a61c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= <6774676+eumiro@users.noreply.github.com> Date: Wed, 30 Nov 2022 20:21:04 +0100 Subject: replace pytz with datetime.timezone and zoneinfo --- mastodon/Mastodon.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 2074224..e0b9257 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -11,7 +11,6 @@ import string import datetime import collections from contextlib import closing -import pytz import requests from requests.models import urlencode import dateutil @@ -3928,11 +3927,11 @@ class Mastodon: """ date_time_utc = None if date_time.tzinfo is None: - date_time_utc = date_time.replace(tzinfo=pytz.utc) + date_time_utc = date_time.replace(tzinfo=datetime.timezone.utc) else: - date_time_utc = date_time.astimezone(pytz.utc) + date_time_utc = date_time.astimezone(datetime.timezone.utc) - epoch_utc = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=pytz.utc) + epoch_utc = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=datetime.timezone.utc) return (date_time_utc - epoch_utc).total_seconds() @@ -3967,7 +3966,7 @@ class Mastodon: if v is not None: try: if isinstance(v, int): - json_object[k] = datetime.datetime.fromtimestamp(v, pytz.utc) + json_object[k] = datetime.datetime.fromtimestamp(v, datetime.timezone.utc) else: json_object[k] = dateutil.parser.parse(v) except: @@ -4023,7 +4022,7 @@ class Mastodon: every time instead of randomly doing different things on some systems and also it represents that time as the equivalent UTC time. """ - isotime = datetime_val.astimezone(pytz.utc).strftime("%Y-%m-%dT%H:%M:%S%z") + isotime = datetime_val.astimezone(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%S%z") if isotime[-2] != ":": isotime = isotime[:-2] + ":" + isotime[-2:] return isotime -- cgit v1.2.3 From bf428f58efbf7989d7771e9edb54fade1009a4e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= <6774676+eumiro@users.noreply.github.com> Date: Wed, 30 Nov 2022 20:44:13 +0100 Subject: refactor: simplify __datetime_to_epoch --- mastodon/Mastodon.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'mastodon') diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index e0b9257..9e30429 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -3925,15 +3925,9 @@ class Mastodon: Assumes UTC if timezone is not given. """ - date_time_utc = None if date_time.tzinfo is None: - date_time_utc = date_time.replace(tzinfo=datetime.timezone.utc) - else: - date_time_utc = date_time.astimezone(datetime.timezone.utc) - - epoch_utc = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=datetime.timezone.utc) - - return (date_time_utc - epoch_utc).total_seconds() + date_time = date_time.replace(tzinfo=datetime.timezone.utc) + return date_time.timestamp() def __get_logged_in_id(self): """ -- cgit v1.2.3