Skip to content

Commit

Permalink
Migrate from pytz (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinHjelmare authored Feb 17, 2022
1 parent cc631cd commit 09fb9ba
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
8 changes: 4 additions & 4 deletions pyicloud/services/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime
from calendar import monthrange

from tzlocal import get_localzone
from tzlocal import get_localzone_name


class CalendarService:
Expand All @@ -27,7 +27,7 @@ def get_event_detail(self, pguid, guid):
(a calendar) and a guid (an event's ID).
"""
params = dict(self.params)
params.update({"lang": "en-us", "usertz": get_localzone().zone})
params.update({"lang": "en-us", "usertz": get_localzone_name()})
url = f"{self._calendar_event_detail_url}/{pguid}/{guid}"
req = self.session.get(url, params=params)
self.response = req.json()
Expand All @@ -49,7 +49,7 @@ def refresh_client(self, from_dt=None, to_dt=None):
params.update(
{
"lang": "en-us",
"usertz": get_localzone().zone,
"usertz": get_localzone_name(),
"startDate": from_dt.strftime("%Y-%m-%d"),
"endDate": to_dt.strftime("%Y-%m-%d"),
}
Expand All @@ -76,7 +76,7 @@ def calendars(self):
params.update(
{
"lang": "en-us",
"usertz": get_localzone().zone,
"usertz": get_localzone_name(),
"startDate": from_dt.strftime("%Y-%m-%d"),
"endDate": to_dt.strftime("%Y-%m-%d"),
}
Expand Down
17 changes: 8 additions & 9 deletions pyicloud/services/photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import base64
from urllib.parse import urlencode

from datetime import datetime
from datetime import datetime, timezone
from pyicloud.exceptions import PyiCloudServiceNotActivatedException
from pytz import UTC


class PhotosService:
Expand Down Expand Up @@ -526,18 +525,18 @@ def created(self):
def asset_date(self):
"""Gets the photo asset date."""
try:
return datetime.fromtimestamp(
self._asset_record["fields"]["assetDate"]["value"] / 1000.0, tz=UTC
)
return datetime.utcfromtimestamp(
self._asset_record["fields"]["assetDate"]["value"] / 1000.0
).replace(tzinfo=timezone.utc)
except KeyError:
return datetime.fromtimestamp(0)
return datetime.utcfromtimestamp(0).replace(tzinfo=timezone.utc)

@property
def added_date(self):
"""Gets the photo added date."""
return datetime.fromtimestamp(
self._asset_record["fields"]["addedDate"]["value"] / 1000.0, tz=UTC
)
return datetime.utcfromtimestamp(
self._asset_record["fields"]["addedDate"]["value"] / 1000.0
).replace(tzinfo=timezone.utc)

@property
def dimensions(self):
Expand Down
6 changes: 3 additions & 3 deletions pyicloud/services/reminders.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import uuid
import json

from tzlocal import get_localzone
from tzlocal import get_localzone_name


class RemindersService:
Expand All @@ -24,7 +24,7 @@ def refresh(self):
"""Refresh data."""
params_reminders = dict(self._params)
params_reminders.update(
{"clientVersion": "4.0", "lang": "en-us", "usertz": get_localzone().zone}
{"clientVersion": "4.0", "lang": "en-us", "usertz": get_localzone_name()}
)

# Open reminders
Expand Down Expand Up @@ -76,7 +76,7 @@ def post(self, title, description="", collection=None, due_date=None):

params_reminders = dict(self._params)
params_reminders.update(
{"clientVersion": "4.0", "lang": "en-us", "usertz": get_localzone().zone}
{"clientVersion": "4.0", "lang": "en-us", "usertz": get_localzone_name()}
)

due_dates = None
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ requests>=2.24.0
keyring>=21.4.0
keyrings.alt>=3.5.2
click>=7.1.2
tzlocal==2.1
pytz>=2020.1
tzlocal>=4.0
certifi>=2020.6.20

0 comments on commit 09fb9ba

Please sign in to comment.