diff --git a/pyproject.toml b/pyproject.toml index 2da1747..0c32d71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "rtmilk" -version = "3.0.0" +version = "3.0.1" description = "Remember The Milk API wrapper" maintainers = [ { name = "Rehan Khwaja", email = "rehan@khwaja.name" } diff --git a/src/rtmilk/_sansio.py b/src/rtmilk/_sansio.py index 23bc147..7ec5a71 100644 --- a/src/rtmilk/_sansio.py +++ b/src/rtmilk/_sansio.py @@ -303,7 +303,9 @@ def In(self, timeline: str, list_id: str, taskseries_id: str, task_id: str, due: if 'has_due_time' in kwargs: kwargs['has_due_time'] = '1' if kwargs['has_due_time'] else '0' if 'due' in kwargs: - if isinstance(kwargs['due'], (date, datetime)): + if isinstance(kwargs['due'], datetime): + kwargs['due'] = _RtmDatetime(kwargs['due']) + elif isinstance(kwargs['due'], date): kwargs['due'] = _RtmDate(kwargs['due']) else: assert isinstance(kwargs['due'], str) @@ -340,7 +342,9 @@ def In(self, timeline: str, list_id: str, taskseries_id: str, task_id: str, star if 'has_start_time' in kwargs: kwargs['has_start_time'] = '1' if kwargs['has_start_time'] else '0' if 'start' in kwargs: - if isinstance(kwargs['start'], (date, datetime)): + if isinstance(kwargs['start'], datetime): + kwargs['start'] = _RtmDatetime(kwargs['start']) + elif isinstance(kwargs['start'], date): kwargs['start'] = _RtmDate(kwargs['start']) else: assert isinstance(kwargs['start'], str) diff --git a/src/rtmilk/client.py b/src/rtmilk/client.py index 58d987c..ecc5e36 100644 --- a/src/rtmilk/client.py +++ b/src/rtmilk/client.py @@ -53,6 +53,13 @@ async def DeleteAsync(self): def FilterDate(date_): return datetime.strftime(date_, '%m/%d/%Y') +def _LoadDate(rtmDate, hasTime): + if rtmDate is None: + return None + if hasTime: + return rtmDate + return rtmDate.date() + def _CreateFromTaskSeries(client, listId, taskSeries): _log.info(f'{taskSeries=}') task0 = taskSeries.task[0] @@ -60,8 +67,8 @@ def _CreateFromTaskSeries(client, listId, taskSeries): result.name._LoadValue(taskSeries.name) result.tags._LoadValue(set(taskSeries.tags.tag) if hasattr(taskSeries.tags, 'tag') else set(taskSeries.tags)) - result.startDate._LoadValue(task0.start.date() if task0.start is not None else None) # None means no change - result.dueDate._LoadValue(task0.due.date() if task0.due is not None else None) # None means no change + result.startDate._LoadValue(_LoadDate(task0.start, task0.has_start_time)) + result.dueDate._LoadValue(_LoadDate(task0.due, task0.has_due_time)) result.complete._LoadValue(task0.completed is not None) result.notes._LoadValue([] if isinstance(taskSeries.notes, list) else taskSeries.notes.note) result.createTime = taskSeries.created diff --git a/tests/test_client.py b/tests/test_client.py index 344e487..cafce78 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,4 +1,4 @@ -from datetime import date, timedelta +from datetime import date, datetime, time, timedelta, timezone from uuid import uuid4 from pydantic import ValidationError @@ -58,6 +58,18 @@ def testClientSync(client): assert newTaskToo.startDate.value == dueDate, 'Start date should have been updated' assert newTaskToo.dueDate.value is None, 'Due date should have been updated' + # Update dates to datetimes + startDateTime = datetime.combine(dueDate, time(12, 42, 0), timezone.utc) # RTM discards the seconds + newTask.startDate.Set(startDateTime) + dueDateTime = datetime.combine(dueDate, time(13, 43, 0), timezone.utc) # RTM discards the seconds + newTask.dueDate.Set(dueDateTime) + + tasksWithTitle = client.Get(f'name:"{name}"') + newTaskToo = tasksWithTitle[0] + assert len(tasksWithTitle) == 1, f'Should be only 1 task with name: "{name}"\n{tasksWithTitle}' + assert newTaskToo.startDate.value == startDateTime, 'Start date should have been updated with the time' + assert newTaskToo.dueDate.value == dueDateTime, 'Due date should have been updated with the time' + newTaskToo.Delete() @mark.asyncio