Skip to content
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

Today and future data-task-due are messy [date-based CSS errors for non-UTC timezones] #2785

Open
3 of 7 tasks
Hexara7777 opened this issue Apr 26, 2024 · 26 comments
Open
3 of 7 tasks
Labels
scope: css styling Changes to styling of elements displayed by Tasks, including search results and individual tasks scope: task dates and times Requests for enhancements to types and formats of dates and times associated with tasks type: bug Something isn't working

Comments

@Hexara7777
Copy link

Hexara7777 commented Apr 26, 2024

Please check that this issue hasn't been reported before.

  • I searched previous Bug Reports didn't find any similar reports.

Expected Behavior

Today should translate to Today only and not tomorrow as well
All future dates should translate to the exact date not shifted

Current behaviour

Those are from the days remaining CSS snippet: #2232
As for the timezone its GMT +3, shal

If today's date is 26th, using the following:

.contains-task-list .task-due[data-task-due="today"]::after { content: "today" }

Will mark both 26th and 27th as today while it's supposed to mark only "Today".

.contains-task-list .task-due[data-task-due="future-1d"]::after { content: "tomorrow" }

Will mark 28th as tomorrow while it's supposed to mark 27th as "Tomorrow" instead.

.contains-task-list .task-due[data-task-due="future-2d"]::after { content: "in 2 days" }

Will mark 29th as in 2 days although 2 days from 26th is 28th.

And so one for all future dates, all shifted by 1 day. While all past ones works right with no problems.

So, is this some kind of bug? How to fix this?

image

Steps to reproduce

Idk how to

Maintainers note: See #2785 (comment) for steps to reproduce.

Which Operating Systems are you using?

  • Android
  • iPhone/iPad
  • Linux
  • macOS
  • Windows

Obsidian Version

1.5.12

Tasks Plugin Version

7.0.0

Checks

  • I have tried it with all other plugins disabled and the error still occurs

Possible solution

Idk

@Hexara7777 Hexara7777 added the type: bug Something isn't working label Apr 26, 2024
@claremacrae
Copy link
Collaborator

Thanks for using Tasks.

There is content in your screenshots that is not provided as text for me to copy, so for reasons explained in the following post, I am unable to investigate:

https://publish.obsidian.md/tasks/Support+and+Help/Report+a+Bug

If you can provide full text, and full numbered steps for a reproduction, as per the above, I will willingly have a look when I have time.

Thank you.

@claremacrae claremacrae added scope: css styling Changes to styling of elements displayed by Tasks, including search results and individual tasks insufficient info Not enough information provided: please use the Issue template labels Apr 26, 2024
@Hexara7777
Copy link
Author

It's not content, it's a tasks query using the following code:

Today + Past

sort by due
not done
show task count
has due date
due in or before today
hide task count
description does not include ?
path does not include Skills
status.type is not NON_TASK

Tomorrow

sort by due
not done
show task count
has due date
due in tomorrow
hide task count
description does not include ?
path does not include Skills
status.type is not NON_TASK

Next 7 days

sort by due
not done
show task count
has due date
due in or before next 7 days
due after tomorrow
hide task count
description does not include ?
path does not include Skills
status.type is not NON_TASK
  1. Create a query
  2. Create a CSS snippet that uses that past, today and future thing, Idk what it's called
    For example this one: Due date styles ✨ #2232
    Or this one: https://publish.obsidian.md/tasks/Advanced/Styling#Colors+for+Due+Today+and+Overdue
  3. You will find that the rendered dates follow the same behavior I described on the first post.

@claremacrae
Copy link
Collaborator

Thanks, but I was very clear in #2784 (comment) that I need the task lines in markdown format too.

@Hexara7777
Copy link
Author

Hexara7777 commented Apr 26, 2024

I see, sorry that's not what I understood the first time, here they are:

- [ ] 0 📅 2024-04-25
- [ ] 1 📅 2024-04-26
- [ ] 2 📅 2024-04-27
- [ ] 3 📅 2024-04-28 
- [ ] 4 📅 2024-04-29 
- [ ] 5 📅 2024-04-30 
- [ ] 6 📅 2024-05-01
- [ ] 7 📅 2024-05-02
- [ ] 8 📅 2024-05-03
- [ ] 9 📅 2024-05-04

This is the result when I have the current time of 1 AM 27th april as of taking this screenshot:
image

And if I manually set my time to 8 PM 26th april (for testing purposes), this is the result:
image

It looks like the first task has a past due date and it works fine, for the others, no difference. And 2 consecutive days count as today.

@claremacrae
Copy link
Collaborator

Thank you.

@claremacrae claremacrae removed the insufficient info Not enough information provided: please use the Issue template label Apr 26, 2024
@Hexara7777
Copy link
Author

Thank you.

You're more than welcome, I have added an image as well. And sorry for earlier misunderstanding.

@claremacrae
Copy link
Collaborator

claremacrae commented Apr 27, 2024

I've tried out what you have supplied, and it gives me very different results from the screenshots that you have posted.


Using the data supplied

These were the steps that I followed. Please note how they are unambiguous, minimal and specific...

  1. Create a new, empty folder
  2. Open that folder as a new vault in Obsidian
  3. Turn on community plugins
  4. Install and enable the Tasks plugin
  5. Create a new snippet file .obsidian/snippets/due-date.css
  6. Add the following content to that snippet file
.contains-task-list .task-due[data-task-due="today"]::after { content: "today" }
.contains-task-list .task-due[data-task-due="future-1d"]::after { content: "tomorrow" }
.contains-task-list .task-due[data-task-due="future-2d"]::after { content: "in 2 days" }
  1. Enable the snippet file in Appearance settings
  2. Set the Base colour scheme to Dark
  3. Create a file called Tasks
  4. Shift+Paste the following content in to that note:
- [ ] 0 📅 2024-04-25
- [ ] 1 📅 2024-04-26
- [ ] 2 📅 2024-04-27
- [ ] 3 📅 2024-04-28 
- [ ] 4 📅 2024-04-29 
- [ ] 5 📅 2024-04-30 
- [ ] 6 📅 2024-05-01
- [ ] 7 📅 2024-05-02
- [ ] 8 📅 2024-05-03
- [ ] 9 📅 2024-05-04

## Query

```tasks
```
  1. View the Tasks note in Source mode, Live Preview, and Reading mode, side-by-side

The time is 02:33 on 27th April, and the result is clearly correct:

image

@claremacrae
Copy link
Collaborator

@Hexara7777 Please follow the numbered steps in my reproduction above, and paste the result in here.

Thanks.

@claremacrae claremacrae added the question Further information is requested label Apr 27, 2024
@Hexara7777
Copy link
Author

Hexara7777 commented Apr 27, 2024

I didn't know that you needed the whole process in such fine details, my apologizes.

I followed your exact steps and here are the results @ 4:56 AM 4/27/2024 GMT+3
image

You can see both 26th and 27th appear as "Today". 26th should be "Yesterday".

@claremacrae
Copy link
Collaborator

Good. Thank you very much.

@claremacrae claremacrae removed the question Further information is requested label Apr 27, 2024
@Hexara7777
Copy link
Author

You're more than welcome! Do you need any logs or something?

@claremacrae
Copy link
Collaborator

No, now it is added to my very long list of things to look at, when I have time.

@claremacrae
Copy link
Collaborator

claremacrae commented Apr 27, 2024

Actually, it would be good to see if the result changes nearer to midday, your time.

Without changing the clock on your PC, could you reopen the test vault at around 11am and again around 1pm, and record the results?

You should close the 3 tabs and reopen them each time, to ensure the results are re-rendered.

And of course paste the result here.

Thanks in advance.

@Hexara7777
Copy link
Author

Hexara7777 commented Apr 27, 2024

I will be out until about 4 PM, can this be a problem? I believe what you're asking about kinda happened around 8 PM yesterday (when I first asked you about this bug).

At around 8-10 PM on 26th April, it showed like that (problem with future dates):
24th -> 2 days ago
25th -> Yesterday
26th -> Today
27th -> Today
28th -> 1 day

At around 2-5 AM on 27th April, it showed like that (problem with past dates):
25th -> 1 day ago
26th -> Today
27th -> Today

28th -> Tomorrow
29th -> 1 day

I think (just a guess) this whole problem is due to the plugin being dealing with hours since/until past/future days rather than using midnight as the point of truth for which day it's now and what days of past/future are.

UPDATE: For some reason, dates now @ 5:56 AM on 4/27/2024 GMT+3 are only messy for yesterday and not all of the past dates:
25th -> 2 day ago
26th -> Today
27th -> Today

28th -> Tomorrow
29th -> 1 day

@claremacrae
Copy link
Collaborator

Yes that’s why I am asking. So far, all the times you’ve quoted are within maybe 4 or 5 hours of your midnight.

I want to know what behaviour you see much closer to your midday.

Also, your changing the clock on your PC introduces another variable or unknown, so I am ignoring any observations made with the clock changed.

Which is why I am asking to know the behaviour close to your actual midday without the clock being changed on your PC.

It’s not a problem your being out today.

Just add the info next time you’re at your PC either side of your midday.

@claremacrae
Copy link
Collaborator

claremacrae commented Apr 27, 2024

UPDATE: For some reason, dates now @ 5:56 AM on 4/27/2024 GMT+3 are only messy for yesterday and not all of the past dates

A couple of things:

  1. I only spotted this UPDATE by luck. GitHub emails me about new comments, but not about any edits to existing ones. So it's best to add new info in new comments, instead of editing existing ones.
  2. Had you closed and re-opened all the tabs containing the note before this 5:56 AM observation? Note my recent comment:

You should close the 3 tabs and reopen them each time, to ensure the results are re-rendered.

@claremacrae claremacrae added the question Further information is requested label Apr 27, 2024
@claremacrae
Copy link
Collaborator

The relevant code is below. It's interesting that .startOf('day') is only added to today and not to the date parameter....

function dateToAttribute(date: Moment) {
const today = window.moment().startOf('day');
const diffDays = today.diff(date, 'days');
if (isNaN(diffDays)) {
return null;
}
if (diffDays === 0) {
return 'today';
}
let result = '';
if (diffDays > 0) {
result += 'past-';
} else if (diffDays < 0) {
result += 'future-';
}
if (Math.abs(diffDays) <= MAX_DAY_VALUE_RANGE) {
result += Math.abs(diffDays).toString() + 'd';
} else {
result += DAY_VALUE_OVER_RANGE_POSTFIX;
}
return result;
}

@claremacrae
Copy link
Collaborator

@Hexara7777 - it's OK, you don't need to do any more tests, thanks. I can reproduce the problem in unit tests.

@claremacrae
Copy link
Collaborator

This edit makes some of the existing tests of data-task-due and related values fail.

Index: tests/global-setup.js
===================================================================
diff --git a/tests/global-setup.js b/tests/global-setup.js
--- a/tests/global-setup.js	(revision 21285ea922eb6fb26b9a971504baa72e825217c6)
+++ b/tests/global-setup.js	(date 1714199793280)
@@ -1,3 +1,3 @@
 module.exports = async () => {
-    process.env.TZ = 'UTC';
+    process.env.TZ = 'America/New_York';
 };

For example, this:

data-task-start="past-3d"

becomes this:

data-task-start="past-2d"

@claremacrae
Copy link
Collaborator

This diff unfortunately did not restore the original behaviour when in 'America/New_York':

Index: src/Renderer/TaskFieldRenderer.ts
===================================================================
diff --git a/src/Renderer/TaskFieldRenderer.ts b/src/Renderer/TaskFieldRenderer.ts
--- a/src/Renderer/TaskFieldRenderer.ts	(revision 21285ea922eb6fb26b9a971504baa72e825217c6)
+++ b/src/Renderer/TaskFieldRenderer.ts	(date 1714201003221)
@@ -60,7 +60,7 @@
 
         function dateToAttribute(date: Moment) {
             const today = window.moment().startOf('day');
-            const diffDays = today.diff(date, 'days');
+            const diffDays = today.diff(date.startOf('day'), 'days');
 
             if (isNaN(diffDays)) {
                 return null;

So there's a lot more exploration needed.

One question to consider is whether the test helper TaskBuilder's handling of timezones on dates is consistent with that of the production code.

@claremacrae claremacrae changed the title Today and future data-task-due are messy Today and future data-task-due are messy [date-based CSS errors for non-UTC timezones] Apr 27, 2024
@claremacrae
Copy link
Collaborator

I've edited the issue description to add the presumed cause.

@claremacrae
Copy link
Collaborator

@Hexara7777 Huge thanks for reporting this. I’m so close to UTC/Greenwich Mean Time that I would never have noticed it.

It also reveals a gap in our automated tests that we fix the time zone to UTC, and don’t test in other time zones.

it’s going to take a while to find safe fixes for this, and any related issues we find as a consequence - but it is important to do so.

@claremacrae claremacrae removed the question Further information is requested label Apr 27, 2024
@Hexara7777
Copy link
Author

@claremacrae You're welcome, I'm glad that you catched the problem, take your time, hope you find the proper solution for it 🙏
If you need any further testing just tell me right away.

@claremacrae
Copy link
Collaborator

Possible related issue in another plugin (MIT licence):

And solution:

@Hexara7777
Copy link
Author

@claremacrae So, this make its solution easier or sooner to come out? :D

@claremacrae
Copy link
Collaborator

@claremacrae So, this make its solution easier or sooner to come out? :D

Only if somebody has time to write failing tests and then work on it...

Not me, I'm currently swamped with too much other Tasks stuff going on....

@claremacrae claremacrae added the scope: task dates and times Requests for enhancements to types and formats of dates and times associated with tasks label May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: css styling Changes to styling of elements displayed by Tasks, including search results and individual tasks scope: task dates and times Requests for enhancements to types and formats of dates and times associated with tasks type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants