diff options
author | Miroslav Šedivý <[email protected]> | 2022-11-30 20:21:04 +0100 |
---|---|---|
committer | Miroslav Šedivý <[email protected]> | 2022-11-30 20:21:04 +0100 |
commit | 5262d58a0b97a04bbc3bd07a1c46c4a6a564a61c (patch) | |
tree | 549f8c109190a88257e2c55bfc6c6e05ce532ff4 /mastodon | |
parent | 53cb42117bd99653f6f86280011cd25299356889 (diff) | |
download | mastodon.py-5262d58a0b97a04bbc3bd07a1c46c4a6a564a61c.tar.gz |
replace pytz with datetime.timezone and zoneinfo
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 11 |
1 files changed, 5 insertions, 6 deletions
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 | |||
11 | import datetime | 11 | import datetime |
12 | import collections | 12 | import collections |
13 | from contextlib import closing | 13 | from contextlib import closing |
14 | import pytz | ||
15 | import requests | 14 | import requests |
16 | from requests.models import urlencode | 15 | from requests.models import urlencode |
17 | import dateutil | 16 | import dateutil |
@@ -3928,11 +3927,11 @@ class Mastodon: | |||
3928 | """ | 3927 | """ |
3929 | date_time_utc = None | 3928 | date_time_utc = None |
3930 | if date_time.tzinfo is None: | 3929 | if date_time.tzinfo is None: |
3931 | date_time_utc = date_time.replace(tzinfo=pytz.utc) | 3930 | date_time_utc = date_time.replace(tzinfo=datetime.timezone.utc) |
3932 | else: | 3931 | else: |
3933 | date_time_utc = date_time.astimezone(pytz.utc) | 3932 | date_time_utc = date_time.astimezone(datetime.timezone.utc) |
3934 | 3933 | ||
3935 | epoch_utc = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=pytz.utc) | 3934 | epoch_utc = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=datetime.timezone.utc) |
3936 | 3935 | ||
3937 | return (date_time_utc - epoch_utc).total_seconds() | 3936 | return (date_time_utc - epoch_utc).total_seconds() |
3938 | 3937 | ||
@@ -3967,7 +3966,7 @@ class Mastodon: | |||
3967 | if v is not None: | 3966 | if v is not None: |
3968 | try: | 3967 | try: |
3969 | if isinstance(v, int): | 3968 | if isinstance(v, int): |
3970 | json_object[k] = datetime.datetime.fromtimestamp(v, pytz.utc) | 3969 | json_object[k] = datetime.datetime.fromtimestamp(v, datetime.timezone.utc) |
3971 | else: | 3970 | else: |
3972 | json_object[k] = dateutil.parser.parse(v) | 3971 | json_object[k] = dateutil.parser.parse(v) |
3973 | except: | 3972 | except: |
@@ -4023,7 +4022,7 @@ class Mastodon: | |||
4023 | every time instead of randomly doing different things on some systems | 4022 | every time instead of randomly doing different things on some systems |
4024 | and also it represents that time as the equivalent UTC time. | 4023 | and also it represents that time as the equivalent UTC time. |
4025 | """ | 4024 | """ |
4026 | isotime = datetime_val.astimezone(pytz.utc).strftime("%Y-%m-%dT%H:%M:%S%z") | 4025 | isotime = datetime_val.astimezone(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%S%z") |
4027 | if isotime[-2] != ":": | 4026 | if isotime[-2] != ":": |
4028 | isotime = isotime[:-2] + ":" + isotime[-2:] | 4027 | isotime = isotime[:-2] + ":" + isotime[-2:] |
4029 | return isotime | 4028 | return isotime |