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

Update the wording for "deadline was" #486

Closed
kliberf opened this issue Jan 18, 2023 · 5 comments
Closed

Update the wording for "deadline was" #486

kliberf opened this issue Jan 18, 2023 · 5 comments

Comments

@kliberf
Copy link

kliberf commented Jan 18, 2023

The wording displayed when a student uploads a solution after the deadline of an assignment is (at least to me) misleading. It can look like

Submitted at: 1/16/2023 15:51 (deadline was 3 hours ago)
Odevzdáno: 16. 1. 2023 15:51 (termín byl před 3 hodinami)

To me, this seems that the deadline was three hours prior to the time I am viewing the webpage (not prior to the submit). I'd like a wording like

Submitted at: 1/16/2023 15:51 (3 hours after the deadline)
Odevzdáno: 16. 1. 2023 15:51 (3 hodiny po termínu)

@krulis-martin
Copy link
Member

I agree entirely, but so far, I have been unable to find a way how to trick react-intl (the <FormattedRelativeTime> component in particular) to avoid using explicit wording (like "ago"). In English, I might be able to hack it using string replacement, but in Czech (thanks to the inflections), such replacement would be impractical. The only option remaining is to write a custom component for relative time formatting (that is quite a lot of work I can currently spend on more pressing issues).

However, if anyone has a tip on how to coerce react-intl to do what we need, I am more than willing to entertain it.

@kliberf
Copy link
Author

kliberf commented Jul 31, 2023

The underlaying Intl.RelativeTimeFormat has formatToParts() method that can be used to extract the inflections and supply custom format. Results look promising, but I don't know if this can be injected into the <FormattedRelativeTime> component.

function test(locale, num, unit)
{
    rtf = new Intl.RelativeTimeFormat(locale, { style: 'long', numeric: 'always' });
    parts = rtf.formatToParts(num, unit);
    return parts[1].value + parts[2].value + (locale == 'cs' ? ' po termínu' : ' after the deadline');
}

for (locale of ['cs', 'en'])
    for (unit of ['minute', 'hour', 'day'])
        for (i = 1; i <= 5; ++i)
            console.log(test(locale, i, unit))

@krulis-martin
Copy link
Member

Technically, it might be better to use https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat directly, as it is quite well-supported already. However, I am not that versed in all its nuances in all languages (or at least cs and en). Yes, the numeric: 'always' option should avoid pitfalls like "yesterday" (instead of 1 day ago), but even then it would require some nontrivial experimenting and subsequent testing to make sure we won't make things worse (relatively to the current state).

So, I am keeping this in the TODO list, but the priority is quite low given its cost-to-benefit ratio.

@krulis-martin
Copy link
Member

I found out that moment.js has I18n as well, I will check it out, whether it will do what we need here...

@krulis-martin
Copy link
Member

The fix will appear in the upcoming release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants