Repository navigation
feat(cal/todo): add COMPLETED property to VTODO (#1797) #2023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RajGahoi
wants to merge
5
commits into
PyCalendar:main
Choose a base branch
from
RajGahoi:feat/todo-completed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7769185
feat(cal/todo): add COMPLETED property to VTODO (#1797)
RajGahoi 7a9bdc7
docs(news): add news fragment for issue #1797
RajGahoi 1e24a15
feat(cal/todo): align COMPLETED property with approved #1803 implemen…
RajGahoi da525e9
docs(todo): apply review suggestions for COMPLETED docstring and news…
RajGahoi 2c98d3a
Merge branch 'main' into feat/todo-completed
stevepiercy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Added property :attr:`Todo.COMPLETED <icalendar.cal.todo.Todo.COMPLETED>` per :rfc:`5545#section-3.8.2.1`. @RajGahoi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| BEGIN:VCALENDAR | ||
| VERSION:2.0 | ||
| PRODID:-//Example Corp.//CalDAV Client//EN | ||
| BEGIN:VTODO | ||
| UID:20070313T123432Z-456553@example.com | ||
| DTSTAMP:20070313T123432Z | ||
| COMPLETED:20070501 | ||
| SUMMARY:Submit Quebec Income Tax Return for 2006 | ||
| CLASS:CONFIDENTIAL | ||
| CATEGORIES:FAMILY,FINANCE | ||
| STATUS:NEEDS-ACTION | ||
| END:VTODO | ||
| END:VCALENDAR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| """Tests for issue #1797: Todo.COMPLETED property.""" | ||
|
|
||
| from datetime import date, datetime, timezone | ||
| from zoneinfo import ZoneInfo | ||
|
|
||
| import pytest | ||
|
|
||
| from icalendar import Todo | ||
| from icalendar.error import InvalidCalendar | ||
|
|
||
| UTC = ZoneInfo("UTC") | ||
|
|
||
|
|
||
| def test_todo_example_completed(todos): | ||
| """Test loading Todo example from todos/completed.ics.""" | ||
| todo = todos.completed | ||
| assert todo.name == "VTODO" | ||
| expected = datetime(2007, 5, 1, 0, 0, tzinfo=UTC) | ||
| assert todo.COMPLETED == expected | ||
|
|
||
|
|
||
| def test_calendar_todo_completed(calendars): | ||
| """Test loading calendar from calendars/todo_completed.ics.""" | ||
| todo = calendars.todo_completed.todos[0] | ||
| expected = datetime(2007, 5, 1, 0, 0, tzinfo=UTC) | ||
| assert todo.COMPLETED == expected | ||
|
|
||
|
|
||
| def test_rfc5545_completed_datetime_example(todos): | ||
| """Test parsing RFC 5545 section 3.8.2.1 example: COMPLETED:19960401T150000Z.""" | ||
| todo = todos.rfc5545_completed | ||
| assert todo.COMPLETED == datetime(1996, 4, 1, 15, 0, tzinfo=UTC) | ||
|
|
||
|
|
||
| def test_completed_get_set_del(): | ||
| """Test getting, setting, and deleting COMPLETED.""" | ||
| todo = Todo() | ||
| assert todo.COMPLETED is None | ||
| assert "COMPLETED" not in todo | ||
|
|
||
| # Set UTC datetime via COMPLETED | ||
| dt_utc = datetime(2026, 9, 16, 12, 0, tzinfo=timezone.utc) | ||
| todo.COMPLETED = dt_utc | ||
| assert todo.COMPLETED == datetime(2026, 9, 16, 12, 0, tzinfo=UTC) | ||
|
|
||
| # Delete via COMPLETED | ||
| del todo.COMPLETED | ||
| assert todo.COMPLETED is None | ||
| assert "COMPLETED" not in todo | ||
|
|
||
| # Set date via COMPLETED | ||
| d = date(2026, 9, 16) | ||
| todo.COMPLETED = d | ||
| assert todo.COMPLETED == datetime(2026, 9, 16, 0, 0, tzinfo=UTC) | ||
|
|
||
| # Set None via COMPLETED | ||
| todo.COMPLETED = None | ||
| assert todo.COMPLETED is None | ||
| assert "COMPLETED" not in todo | ||
|
|
||
|
|
||
| def test_todo_new_with_completed(): | ||
| """Test creating a new Todo with the completed parameter.""" | ||
| dt_utc = datetime(2026, 9, 16, 14, 30, tzinfo=timezone.utc) | ||
| todo = Todo.new(summary="Test Todo", completed=dt_utc) | ||
| assert todo.COMPLETED == datetime(2026, 9, 16, 14, 30, tzinfo=UTC) | ||
|
|
||
| # With date | ||
| d = date(2026, 9, 16) | ||
| todo_date = Todo.new(summary="Test Todo", completed=d) | ||
| assert todo_date.COMPLETED == datetime(2026, 9, 16, 0, 0, tzinfo=UTC) | ||
|
|
||
| # Without completed | ||
| todo_none = Todo.new(summary="Test Todo") | ||
| assert todo_none.COMPLETED is None | ||
| assert "COMPLETED" not in todo_none | ||
|
|
||
|
|
||
| def test_invalid_completed(): | ||
| """Test setting invalid types or invalid values raises appropriate errors.""" | ||
| todo = Todo() | ||
| with pytest.raises(TypeError): | ||
| todo.COMPLETED = "not a date" | ||
|
|
||
| with pytest.raises(TypeError): | ||
| todo.COMPLETED = 12345 | ||
|
|
||
| # Invalid value directly in component dict | ||
| todo["COMPLETED"] = 12345 | ||
| with pytest.raises(InvalidCalendar): | ||
| _ = todo.COMPLETED |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| BEGIN:VTODO | ||
| UID:20070313T123432Z-456553@example.com | ||
| DTSTAMP:20070313T123432Z | ||
| COMPLETED;VALUE=DATE:20070501 | ||
| SUMMARY:Submit Quebec Income Tax Return for 2006 | ||
| CLASS:CONFIDENTIAL | ||
| CATEGORIES:FAMILY,FINANCE | ||
| STATUS:NEEDS-ACTION | ||
| END:VTODO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| BEGIN:VTODO | ||
| UID:20070313T123432Z-456553@example.com | ||
| DTSTAMP:20070313T123432Z | ||
| COMPLETED:19960401T150000Z | ||
| END:VTODO |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.