Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@karwosts
Copy link
Contributor

As per the previous comment here: home-assistant/core#145820 (comment), I have attempted to add completed timestamp tracking to this library.

Hope I found the right spot for the logic. Thanks for taking the time to take a look.

# name: test_edit_todo.3
list([
dict({
'created': '2022-09-03T09:38:25+00:00',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably unrelated to this PR but this seems like maybe a bug, the created timestamp is advancing on every edit to the previous value of dtstamp, not maintaining the original creation date.

@codecov
Copy link

codecov bot commented Oct 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.10%. Comparing base (0708fc2) to head (631e381).
⚠️ Report is 22 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #528   +/-   ##
=======================================
  Coverage   97.10%   97.10%           
=======================================
  Files          53       53           
  Lines        3208     3215    +7     
=======================================
+ Hits         3115     3122    +7     
  Misses         93       93           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rafalkrupinski
Copy link

Not too happy that the new code changes values without user explicitly asking.

@allenporter
Copy link
Owner

Not too happy that the new code changes values without user explicitly asking.

The store is meant to be a higher level API does that handles changing values. The lower level APIs can still be used to avoid this behavior. Do you have a use case for wanting to mark an item completed without setting the completed timestamp? or do you have another concern?

@rafalkrupinski
Copy link

No, I guess I didn't have a good understanding of its purpose. Thanks

Copy link
Owner

@allenporter allenporter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, appreciate this contribution and flagging the issue with the existing timestamps.

Comment on lines 996 to 997
],
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would help reading the snapshots to have the ids set:

Suggested change
],
)
],
ids=["no_status", "needs_action", "completed", "completed_with_timestamp"],
)

{"status": "COMPLETED", "completed": '2020-01-01T00:00:00+00:00',},
],
)
def test_add_and_delete_todo(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make a new testwith a descriptive name for what it's trying to accomplish rather than tacking on to an existing test. Having a focused test on exercising completion timestamp will make it more obvious if there is a regression the motivation behind the test rather than combining it with other things. For example, we don't need to be testing deletion at the same time.

Something like test_add_with_status would be good.

Same below for the edit tests, something like test_edit_with_status would be good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated as requested, moved to standalone tests.

ical/store.py Outdated
and item.status == TodoStatus.COMPLETED
):
update["completed"] = (
item.dtstamp.replace(microsecond=0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here? It seems useful and desirable to use the exact same value as item.dtstamp

Copy link
Contributor Author

@karwosts karwosts Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that rfc5545 says:

Fractions of a second are not supported by this format

I thought it would be somewhat odd that we would store the microseconds for the item in memory. That would have side effects like where a todo item would return a completed value with a fraction of a second for some time after it was completed, but then once a system was restarted and the items were reloaded from the storage format, the microseconds would disappear.

I thought it would be better to be consistent that a completed timestamp never has fractions of a second, because otherwise the completed timestamp will be unexpectedly different on a restart.

Copy link
Owner

@allenporter allenporter Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, agree the spec doesn't support anything lower than seconds. My impression is that what you are identifying applies to all fields of the same value type and not specifically to completed (e.g. what about the same thing for dtstamp). I don't think this field should have a different behavior than other fields. if you'd like to do something about this for the entire code base in a separate PR, perhaps -- but even then I think it's a good catch, though not sure it's worth it.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An approach that could work is instead of updating each field individually is to update the dtstamp_factory which is used to generate all timestamps:

def dtstamp_factory() -> datetime.datetime:
(again seems like an issue for a separate PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the replace-microsecond and just went back to using the original timestamp.

Copy link
Owner

@allenporter allenporter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution! Very much appreciated.

@allenporter allenporter merged commit 5770b9a into allenporter:main Oct 29, 2025
7 checks passed
@karwosts karwosts deleted the completed-todo branch October 29, 2025 02:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants