-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Fix due dates not rendering with a one-off date #29698
Conversation
Some timestamps are not meant to be localized in the user's timezone, only in their language. This is true for due date timestamps. These include a specific year, month, and day combination. If a user in one timezone sets the date YYYY-MM-DD, another user should see the same date, regardless of their timezone. So when a relative-time element has their datetime attribute specified only as YYYY-MM-DD, we will update it to YYYY-MM-DD midnight in the user's timezone. When the date is rendered, the only localization that will happen is the language. For all relative-time elements, if their datetime attribute is YYYY-MM-DD, we will update it to YYYY-MM-DD midnight in the user's timezone Signed-off-by: Yarden Shoham <git@yardenshoham.com>
I wish I could make the datetime replacement as early as possible, ideally before the first Can I change the behavior of the relative time web component? Maybe go with a mutation observer? |
Not directly, unless we fork it. Ideally you would contribute your fix upstream if it is deemed an acceptable change there. We could wrap the custom element an another custom element of ours, but this will be a very complex effort I assume. |
I think #29034 (comment) would be a much better solution than to wrestle with this in the frontend. |
How would #29034 (comment) solve this? Today we already send only the date without the time... |
I tried. I couldn't make it work. Let's go ahead and land as-is to fix the bug as soon as possible. |
Do we? Then the value is interpreted incorrectly on the frontend. A date must be interpreted as a date, not a datetime.
Sorry, but this requires deeper investigation on why we interpret date as datetime. Does |
Yes, |
That's where it goes wrong. There simply is no time component to a date, interpreting as I could easily come up with a webcomponent that accepts a date in a attribute and renders it in the document's locale. |
But we need it for the language localization |
Example of such a component: function toLocaleDate(date) {
return date.toLocaleString(document.documentElement.lang, {year: 'numeric', month: 'long', day: 'numeric'});
}
window.customElements.define('locale-date', class extends HTMLElement {
connectedCallback() {
this.textContent = toLocaleDate(this.getAttribute('data-date'));
}
}); |
I'm not completely sure above is right because it goes through JS |
I don't think we should have 2 different components to render localized dates |
Well it entirely depends whether |
Right, but this PR fixes it. |
I can't accept such hacks without reading into |
Yeah but they only render English, never other formats |
Yes, that's why we need #29698 (comment). |
So I read through https://github.com/github/relative-time-element?tab=readme-ov-file#relative-time-element and I'm convinced it's just not meant for date rendering. It accepts only I can likely create the webcomponent in another PR if you are unwilling to do, I strongly believe it's the right way and we should not abuse |
I'd rather not create the component myself, go ahead and create a PR for that. Maybe until you do though we could merge this one |
Where does the backend currently render these dates? Is it here? https://github.com/go-gitea/gitea/blob/main/modules/timeutil/datetime.go |
gitea/routers/web/repo/issue.go Line 2312 in 7f856d5
|
Thanks, so for rendering we want to only use |
Yeah, this PR reverts the automatic timezone conversion done by |
So I tried implementing like above but the implementation suffers the same time zone problem. The root of the problem is that when passing a So I think this workaround is acceptable until we have Temporal.PlainDate in a few years or so 😆, which will cleanly solve it. Maybe date support could also be contributed to |
On the other hand, this solution has a almost unacceptable flash of incorrect content because it loads as part of the main JS bundle. |
almost |
Can't get rid of that content flash, so I just added this simple negative offset calculation to my component and now it works flawlessly. |
Yeah #29725 is better because there's no content flash |
Alternative to: #29698 Fixes: #29034 <img width="278" alt="image" src="https://github.com/go-gitea/gitea/assets/115237/12ecd967-2723-410d-8a28-a1b0f41b7bba"> It also fixes a secondary issue that we were showing timestamp tooltips over date, which makes no sense, so these are now gone as well: <img width="284" alt="image" src="https://github.com/go-gitea/gitea/assets/115237/a70432f3-97b6-41e6-b202-b53b76924a66">
Alternative to: go-gitea#29698 Fixes: go-gitea#29034 <img width="278" alt="image" src="https://github.com/go-gitea/gitea/assets/115237/12ecd967-2723-410d-8a28-a1b0f41b7bba"> It also fixes a secondary issue that we were showing timestamp tooltips over date, which makes no sense, so these are now gone as well: <img width="284" alt="image" src="https://github.com/go-gitea/gitea/assets/115237/a70432f3-97b6-41e6-b202-b53b76924a66">
Backport #29725 by @silverwind Alternative to: #29698 Fixes: #29034 <img width="278" alt="image" src="https://github.com/go-gitea/gitea/assets/115237/12ecd967-2723-410d-8a28-a1b0f41b7bba"> It also fixes a secondary issue that we were showing timestamp tooltips over date, which makes no sense, so these are now gone as well: <img width="284" alt="image" src="https://github.com/go-gitea/gitea/assets/115237/a70432f3-97b6-41e6-b202-b53b76924a66"> Co-authored-by: silverwind <me@silverwind.io>
Some timestamps are not meant to be localized in the user's timezone, only in their language. This is true for due date timestamps. These include a specific year, month, and day combination. If a user in one timezone sets the date YYYY-MM-DD, another user should see the same date, regardless of their timezone. So when a relative-time element has their datetime attribute specified only as YYYY-MM-DD, we will update it to YYYY-MM-DD midnight in the user's timezone. When the date is rendered, the only localization that will happen is the language.
For all relative-time elements, if their datetime attribute is YYYY-MM-DD, we will update it to YYYY-MM-DD midnight in the user's timezone.
Demo GIFs
In these GIFs, I do the following:
Before
After