β Inconsistent due dates: π in task text vs task.due metadata #3415
-
Hi everyone, I'm running the following DataviewJS code to compare the due date from task metadata (task.due) with the π date written in the task text: // dataviewjs code block, formatted in js fenced code block for readability
// π Folders to ignore when loading tasks
const ignoredFolders = ["zzz/", "zzz tests/"];
// π
Helper function to extract a date from task text using a given regex
function extractDate(taskText, regex) {
let m = regex.exec(taskText);
return m ? m[1] : null;
}
// π Load all tasks from files, excluding those in ignored folders
let tasks = dv.pages()
.where(p =>
p.file.tasks &&
p.file.tasks.length > 0 &&
!ignoredFolders.some(folder => p.file.path.toLowerCase().startsWith(folder.toLowerCase()))
)
.flatMap(p => p.file.tasks.map(task => ({ ...task, file: p.file })));
// π Filter tasks where the due date from metadata differs from the π
date in task text
let inconsistentTasks = tasks.filter(task => {
let dueFromText = extractDate(task.text, /π
\s?(\d{4}-\d{2}-\d{2})/);
let dueFromMeta = task.due ? moment(task.due).format("YYYY-MM-DD") : null;
return dueFromText && dueFromMeta && dueFromText !== dueFromMeta;
});
/*
π§ Why differences may occur:
- task.due is set by the parser (e.g. Tasks plugin), which may detect due dates differently
than what is visually shown via π
in the text.
- If multiple dates are present in the task (e.g. β
, π
, β), the plugin might pick the wrong one.
- The π
emoji might just be part of the text and not actually parsed as metadata.
- Some task formats might confuse the parser or be partially supported.
*/
// π¨ Show all tasks with inconsistent due dates
if (inconsistentTasks.length > 0) {
dv.paragraph(`β Found ${inconsistentTasks.length} tasks with inconsistent π
in text vs metadata:\n`);
dv.list(inconsistentTasks.map(task => {
let dueFromText = extractDate(task.text, /π
\s?(\d{4}-\d{2}-\d{2})/);
let dueFromMeta = task.due ? moment(task.due).format("YYYY-MM-DD") : "β";
return `[[${task.file.path}]] β ${task.text}
π
from text: **${dueFromText}**, from metadata: **${dueFromMeta}**`;
}));
} else {
dv.paragraph("β
All good β no differences found between π
in text and `task.due` metadata.");
} In my vault, Iβm getting quite a few tasks where these two dates differ β meaning the π date visible in the task is not the same as the task.due value returned by Dataview. Hereβs what Iβm doing: I use the internal Obsidian Tasks plugin, including its task edit popup. I also occasionally use the βpostponeβ action directly from the task query result. π§ Am I doing something wrong here? Any clarification would be super helpful. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 9 replies
-
Sorry but that is way too long a set of code, written for another plugin, to expect anyone here to be able to debug it. Suggestions
Example reproduction:
|
Beta Was this translation helpful? Give feedback.
-
(I've got a label for Insufficient Information - currently considering creating one for Too Much Information π ) |
Beta Was this translation helpful? Give feedback.
-
Actually I have labelled it "Insufficient Information" because it is not clear to me exactly what Tasks behaviour it is talking about... And I cannot provide support for dataview! |
Beta Was this translation helpful? Give feedback.
-
Did you mean to log this in Dataview? |
Beta Was this translation helpful? Give feedback.
-
It is certainly expected that Tasks and Dataview would agree in how they parse the date fields. I donβt know if they would differ in how they treat any time component on the date objects. |
Beta Was this translation helpful? Give feedback.
-
well, why not give some examples here then? |
Beta Was this translation helpful? Give feedback.
-
Availability of helpHi, I am happy to try and help, but just to set expectations, I do not currently have time to go through that quantity of detail above, so I can only give you pointers to things it reminds me of. What is wrong?
Honestly, maybe it's clear above, but I have not been able to figure out, in a reasonable amount of time, whether you are seeing the unexpected results in any or all of these:
Possible cause: Unicode Variant SelectorsI do know that, through maintaining Tasks, I learned about hidden, invisible characters in Emojis called something like Unicode Variant Selectors, which meant that some extra characters can be next to Emojis, and cause simple regular expressions to not match as expected. Tasks bug reports:
Tasks PRs:
I don't remember the details, but you may find in those links:
If it is a dataview problemIf it is a dataview problem, it would be best to move this discussion to that repo, please. Do of course add a link here, to the new location of the discussion. What nextIf that doesn't help, please give me:
Thanks, and good luck. |
Beta Was this translation helpful? Give feedback.
-
tl;dr
How to find out what is going on?Your A general approach here is to make visible the detail of the calculations. I created the following file: - [ ] task 1 π
2025-04-07
- [ ] task 2 π
2025-04-07
- [ ] task 3 π
2025-04-08
- [ ] task 4 π
2025-04-08
## Fixed code
```dataviewjs
// Format due date from metadata
let dueMeta = t => t.due ? moment(t.due).format("YYYY-MM-DD HH:mm:ss") : null;
// Extract π
date from task text
let dueText = t => (/π
\uFE0F?\s?(\d{4}-\d{2}-\d{2})/.exec(t.text)?.[1] ?? null);
function format(label, value) {
return `<tt>${label}='${value}'; </tt>`;
}
// Show data for all tasks in this file
dv.list(dv.current().file.tasks.map(t =>
format('t.text' , t.text) +
format('t.due' , t.due) +
format('moment(t.due)', moment(t.due)) +
format('dueText(t)' , dueText(t)) +
format('dueMeta(t)' , dueMeta(t))
));
``` Things to note:
So what is going on?Here is what the output looks like: This shows that:
It looks like you should be using Dataview's |
Beta Was this translation helpful? Give feedback.
tl;dr
How to find out what is going on?
Your
dueMeta
anddueText
functions do several things in one line - so we need to work out which aspects of them are the problem.A general approach here is to make visible the detail of the calcβ¦