Can days of week in a query remain constant during the week? #1176
-
On a Dashboard page, I'd like to query my active tasks. For me, these are those that are due this week. I like starting my week off on Monday.
This seems to work like At the start of the week this works fine, but here it is Friday and my query is empty because both Monday and Next Monday are three days from now. I understand that the days of the week go towards the closest based on the current day. Is there any setting or technique where we can make these days stick with the current week? On a Friday: 2022-09-23 I've got a little markdown file for testing though the dates would need to be altered for future weeks. I really appreciate the Tasks plugin. Thank you so much for maintaining and enhancing it. |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 13 replies
-
Hi @kenfeliciano, Thank you for a very clear and focused question, and a very helpful example file. I can reproduce the behaviour you describe, and I haven't been able to find a way to get this to work using pure Tasks queries, unfortunately. As far as I know, this is not possible. I experimented with things like 'Friday this week'. I haven't looked hard, but I think there are other people asking the same thing: #422 How to solve this - with new features.I can't just change the behaviour for all queries, as this would break some existing queries. So the options for Tasks are:
Any suggestions for Workaround 1 - fixed datesIn the past, people asking this have been generally pointed to use some kind of daily notes plugin, with a template that calculates the dates - see Daily Agenda in the Tasks docs for ideas. Workaround 2 - use dataview to create the Tasks queryIn Using Dataview to generate Tasks blocks - safe and convenient I show how to use Dataview's For the time being, I'm afraid the only thing I can think of is to use dataview to calculate the dates you want, and then use them in your Tasks query. Reason for the current behaviourTasks uses the chrono library to parse date strings. In the source code, the interesting bit is here: obsidian-tasks/src/Query/DateParser.ts Lines 3 to 14 in 11a3712 Almost all the uses of That is the cause of this inability to write a simple Tasks query for tasks in a particular week, that works throughout the whole week. |
Beta Was this translation helpful? Give feedback.
-
Maybe I'm missing something, but strangely, it seems to work for me. I have tried this:
But this also works:
Or just:
Maybe you tested with an older plugin version that uses an older chrono version? Because there was a relevant change in the latest version of chrono. |
Beta Was this translation helpful? Give feedback.
-
There's been a PR to update to the new chrono that I hadn't got to. #1061. |
Beta Was this translation helpful? Give feedback.
-
To make things a bit more confusing, I found that it actually works as I described above with chrono 2.3.9 which is the version that is currently used in Obsidian Tasks 1.14.0. When I upgrade to chrono 2.4.1, this no longer works and I need to change it like this to make it work again:
I think there is a difference in how "this sunday" is interpreted. In 2.3.9 it was the Sunday at the beginning of the week, in 2.4.1 it is the closest Sunday, which can be Sunday at the end of the week. To refer to the Sunday at the beginning of the week, you need to refer to the With chrono 2.4.1 you can also phrase it like this:
|
Beta Was this translation helpful? Give feedback.
-
I would like to document what's been learned here - huge thanks, @Cito! Thing is, if I'm going to document it, I think it makes sense to update to 2.4.1 and document the new behaviour of chrono - 2.4.1 - rather than the old one - 2.3.9. If I document the old version, we'll be stuck on that for good, perhaps. I'm considering make the next release Tasks 2.0, as this is really a breaking change (and I think chrono should have bumped the major version too!) Anyway, @Cito and @kenfeliciano - I'd appreciate your views. |
Beta Was this translation helpful? Give feedback.
-
Suggestion: Maybe we can add a constant that contains the currently used version of chrono, and also a setting that stores the last used version (if missing, it would be considered to be 2.3.9). When the plugin loads, we check whether the two differ, and in this case we show a warning with a link to the chrono changelog or a special page in our docs that lists all incompatible changes in chrono. After showing the warning, we update the chrono version in the settings, so that the warning will not appear again. Of course when updating chrono to an incompatible version, we should also update at least the minor version of Tasks. A new major version is not really required in my view. In any case what we should not do is wait for the next major version and only then update chrono. I think the earlier we update, the fewer users will have relied on the old chrono. |
Beta Was this translation helpful? Give feedback.
-
@claremacrae I so agree with you that chrono should have bumped a major revision. I say that because of my tests breaking though, not theirs. @Cito I agree that for my purposes, I'll be able to use last Sunday and 8 days after last Sunday to get the date range I want with 2.4.1 and I thank you for that alternative. I apologize for getting back late on this. You all move fast! I thought I found a bug in chrono that broke all my tests but I guess my tests were the problem. When I made them better, they now pass in 2.3.9 and 2.4.1. The only difference is, in 2.4.1, Sunday is at the end of the week instead of the start. This is a much shorter comment now! But, now I'm ready to just be retired again :) I use the same exact code that works in a jest test in a tiny little node program and chrono gives me the wrong answer.
I know almost nothing about running things in I'm enclosing my tests for chrono. I'm testing every day in every prior, current, and next week and they all work. Perhaps these will be useful somehow. I can try and help with test cases or documentation. I really do like this project. |
Beta Was this translation helpful? Give feedback.
-
Now that there is an https://obsidian-tasks-group.github.io/obsidian-tasks/queries/explaining-queries/. I may write up some systematic tests to get good coverage of a wide range of date filters, and how they are interpreted on different days of the week. |
Beta Was this translation helpful? Give feedback.
-
Just to note that a lot of work has been done recently to give more control over date searches, and to search for date ranges. See the several sections in the docs at: Also, the various tables at the end of that page show how a range of date queries are now interpreted. So I'm going to close this. If there are specific cases that still don't work, then bug reports for individual problem cases would be very welcome. |
Beta Was this translation helpful? Give feedback.
Maybe I'm missing something, but strangely, it seems to work for me. I have tried this:
But this also works:
Or just:
Maybe you tested with an older plugin version that uses an older chrono version? Because there was a relevant change in the latest version of chrono.