obsidian-tasks icon indicating copy to clipboard operation
obsidian-tasks copied to clipboard

Current time filter

Open czhad opened this issue 1 year ago • 6 comments

⚠️ Please check that this feature request hasn't been suggested before.

  • [X] I searched previous Ideas in Discussions didn't find any similar feature requests.
  • [X] I searched previous Issues didn't find any similar feature requests.
  • [X] I am only requesting a single feature. Multiple changes should be split into individual requests, with links between them.
  • [X] I believe my requested feature will be generally applicable to other users, not just me: it is not uniquely tied to my personal workflow.

🔖 Feature description

Hi, I really appreciate the Tasks plugin, and I am using it daily. Given the vast number of tasks I have to deal with, there's one thing that could make my life easier, and might be useful for others as well.

I would like to be able to have a function that would allow me to filter displayed tasks according to current time and/or day of week. E.g. work tasks could be displayed only on work days between 8am and 5 pm, and private tasks should only be displayed outside of the work hours, but it should be flexible enough to allow for any combination of times that could be used with any combination of other conditions.

My idea is to use tags to mark tasks for certain time periods and combine them with time ranges in tasks conditions.

✔️ Solution

I suppose it would make sense to define time ranges either globally in the plugin settings, or in a separate task-definition blocks anywhere in the vault, e.g.

time-range workingtimerange = mon tue wed thu fri AND (8:00 to 16:59)
time-range outsideworkrange = NOT (workingtimerange)
time-range projectXmeeting = (2023-11-22 *14) AND (9:00 to 11:00)
time-range lunchtimerange = 11:30 to 12:15
time-range weekend = sat sun

Then, suppose we have the following tasks:

- [ ] task 1: this is a work-time task #workingtime 📅 2023-11-22
- [ ] task 2: this is a non-work-time task #afterwork 📅 2023-11-22
- [ ] task 3: buy flowers #lunchtime 📅 2023-11-22
- [ ] task 4: finish your book #weekend
- [ ] task 5: projectX task review #projectX

and the following task block:

```tasks
not done
(due today) OR (no due date)
((tag includes #workingtime) AND (current time is within workingtimerange) AND (current time is not within lunchtimerange)) OR ((tag includes #afterwork) AND (current time is within outsideworkrange)) OR ((tag includes #lunchtime) AND (current time is within lunchtimerange)) OR ((tag includes #weekend) AND (current time is within weekend)) OR ((tag includes #projectX) AND (current time is within projectXmeeting))
```

This would result in the following:

  • task 1 would be displayed on the 22nd November 2023 ONLY WHEN the devices's current time is within workdays 8am to 4:59pm except 11:30am to 12:15pm,
  • task 2 would be displayed only before or after working hours or on weekends (which actually means never, because 22nd November 2023 is not on a weekend)
  • task 3 whould only be displayed between 11:30 and 12:15 on 22nd November 2023
  • task 4 would be displayed on weekends
  • task 5 would be displayed every 14th day starting on 2023-11-22 (i.e. every other wednesday) between 9:00 and 11:00

(Note: I am borrowing the day of week and periodic repetition syntax from remind https://linux.die.net/man/1/remind – it could serve as an inspiration for even more time definition options.)

❓ Alternatives

An advanced user could be able to use a custom js filter for this, but it would be difficult to maintain over a large vault with many tasks blocks and probably not usable for any common user, including myself.

Also, my current solution is to have separate pages with task blocks for differently tagged tasks, but it requires me to remember to open the correct task list at a correct time, and I am not really good at that. :)

📝 Additional Context

Caveat: As the task 2 example shows, it would be rather easy for a distracted user to define a task that never gets displayed. There should be a filter available to look for such tasks anywhere in the vault.

One more caveat: I'm not sure how scalable this would be for people with many constantly changing projects, but for people like me who have to deal with several long-time projects, it would seem to be good enough.

Also, it would be much easier to use if combined with macro definitions such as those I suggested in #2443 yesterday:

macro @wrktime = ((tag includes #workingtime) AND (current time is within workingtimerange))
macro @freetime = ((tag includes #afterwork) AND (current time is within outsideworkrange))
macro @weekends = ((tag includes #weekend) AND (current time is within weekend))
macro @nlt = (current time is not within lunchtimerange))
macro @pX = ((tag includes #projectX) AND (current time is within projectXmeeting))
macro @dt = ((due today) OR (no due date)) AND (not done)

With the macros, the same task filter would be defined more easily:

@dt
((@wrktime) AND (@nlt)) OR (@freetime) OR (@wekends) OR (@pX)

czhad avatar Nov 23 '23 09:11 czhad

Correction: The first time-range definition should probably use parentheses around weekdays to be in line with Tasks logic:

time-range workingtimerange = (mon tue wed thu fri) AND (8:00 to 16:59)

czhad avatar Nov 23 '23 09:11 czhad

Have you looked at the custom filters in Tasks? I expect it would be possible using them already.

You would need to reopen query files when crossed a time boundary as it only automatically updated at midnight.

claremacrae avatar Nov 23 '23 09:11 claremacrae

Thank you for the suggestion.

claremacrae avatar Nov 23 '23 09:11 claremacrae

Have you looked at the custom filters in Tasks? I expect it would be possible using them already.

Yes, unfortunately I am not a programmer and I'm afraid this would be way over my abilities.

You would need to reopen query files when crossed a time boundary as it only automatically updated at midnight.

This would be a problem, although I am opening my daily notes quite often. I'm not sure how to solve this—either via manual refreshes (refresh button in the task listing?), or user-definable periodic refreshes? Would that be possible?

czhad avatar Nov 23 '23 09:11 czhad

Yes, as a workaround this is all doable with custom date filters so you don't need to wait until this is implemented, if ever...

When you get it working, there are two basic ways to re-use it across multiple queries....

  1. Write individual Templater templates for each of the searches, so you can easily paste them in to new queries.

  2. If you had programming experience [I've just seen your previous reply], you could bundle the code up for re-using across different query blocks using dataview views. For now, the best I can do to point towards using dataview views is this example of how I create Eisenhower views on my tasks - written up on discord.

claremacrae avatar Nov 23 '23 09:11 claremacrae

Yes, unfortunately I am not a programmer and I'm afraid this would be way over my abilities.

OK I'm currently completely over-burdened with Tasks work and support... In earlier times I might have been able to write the code for you, but not now.

You could try asking in #task-management channel on Obsidian Discord and see if someone can help assemble something, or if someone is even doing this already....

claremacrae avatar Nov 23 '23 09:11 claremacrae