Skip to content

Commit

Permalink
Allow aware datetimes for last_sync parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
rkhwaja committed May 27, 2024
1 parent 81ebddd commit b8fe291
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "rtmilk"
version = "2.0.0"
version = "2.1.0"
description = "RTM API wrapper"
authors = ["Rehan Khwaja <[email protected]>"]
license = "MIT"
Expand Down
12 changes: 9 additions & 3 deletions src/rtmilk/_sansio.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from datetime import date, datetime
from datetime import date, datetime, UTC
from hashlib import md5
from logging import getLogger
from pprint import pformat
Expand Down Expand Up @@ -261,8 +261,14 @@ def Out(cls, **rsp):
class TasksGetList(AuthorizedCall):
def In(self, list_id: str | None = None, filter: str | None = None, last_sync: datetime | None = None):
kwargs = _RebuildArgs(list_id=list_id, filter=filter, last_sync=last_sync)
if 'last_sync' in kwargs and isinstance(kwargs['last_sync'], (datetime)):
kwargs['last_sync'] = _RtmDatetime(kwargs['last_sync'])
if 'last_sync' in kwargs:
if not isinstance(kwargs['last_sync'], (datetime)):
raise TypeError('last_sync should be a datetime')
lastSyncDt = kwargs['last_sync']
if lastSyncDt.tzinfo is not None:
# switch to naive datetime in UTC
lastSyncDt = lastSyncDt.astimezone(UTC).replace(tzinfo=None)
kwargs['last_sync'] = _RtmDatetime(lastSyncDt)
return self.CommonParams('rtm.tasks.getList', **kwargs)

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions tests/test_api_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, UTC
from logging import info
from random import randint
from uuid import uuid4
Expand Down Expand Up @@ -222,7 +222,7 @@ def test_get_list(api, task): # noqa: ARG001
info(f'List ID: {list_.id}')

def test_last_sync(api, taskCreatorAPI):
start = datetime.utcnow()
start = datetime.now(UTC)
noChange = api.TasksGetList(last_sync=start)
assert noChange.tasks.list is None, 'No tasks added at the start'
task1 = taskCreatorAPI.Add(f'task 1 {uuid4()}')
Expand Down

0 comments on commit b8fe291

Please sign in to comment.