-
Notifications
You must be signed in to change notification settings - Fork 13
Track completed timestamp for TodoItem #528
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
Conversation
tests/__snapshots__/test_store.ambr
Outdated
| # name: test_edit_todo.3 | ||
| list([ | ||
| dict({ | ||
| 'created': '2022-09-03T09:38:25+00:00', |
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.
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
Not too happy that the new code changes values without user explicitly asking. |
The |
|
No, I guess I didn't have a good understanding of its purpose. Thanks |
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.
Thank you, appreciate this contribution and flagging the issue with the existing timestamps.
| ], | ||
| ) |
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.
It would help reading the snapshots to have the ids set:
| ], | |
| ) | |
| ], | |
| ids=["no_status", "needs_action", "completed", "completed_with_timestamp"], | |
| ) |
tests/test_store.py
Outdated
| {"status": "COMPLETED", "completed": '2020-01-01T00:00:00+00:00',}, | ||
| ], | ||
| ) | ||
| def test_add_and_delete_todo( |
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.
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.
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.
Updated as requested, moved to standalone tests.
ical/store.py
Outdated
| and item.status == TodoStatus.COMPLETED | ||
| ): | ||
| update["completed"] = ( | ||
| item.dtstamp.replace(microsecond=0) |
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.
Why is this here? It seems useful and desirable to use the exact same value as item.dtstamp
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.
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.
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.
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.
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.
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:
Line 24 in 846a396
| def dtstamp_factory() -> datetime.datetime: |
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.
I removed the replace-microsecond and just went back to using the original timestamp.
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.
Thank you for the contribution! Very much appreciated.
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.