Skip to content

Commit

Permalink
Read and write start and due times correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
rkhwaja committed Oct 16, 2024
1 parent d4399d3 commit 9128781
Show file tree
Hide file tree
Showing 4 changed files with 29 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 @@
[project]
name = "rtmilk"
version = "3.0.0"
version = "3.0.1"
description = "Remember The Milk API wrapper"
maintainers = [
{ name = "Rehan Khwaja", email = "[email protected]" }
Expand Down
8 changes: 6 additions & 2 deletions src/rtmilk/_sansio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 9 additions & 2 deletions src/rtmilk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,22 @@ 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]
result = Task(client, listId, taskSeries.id, task0.id)

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
Expand Down
14 changes: 13 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9128781

Please sign in to comment.