-
-
Notifications
You must be signed in to change notification settings - Fork 165
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
Use time strings formatted for the locale for homework set dates. #1615
Conversation
This seems to work as much as I can tell. I would love to see someone who uses this in a non-English language test it out though. |
7c4f70b
to
8a49479
Compare
Hello, thank you for working on this issue. I will check the patch. However, I do not have last WeBWorK version running and after upgrade my apache2 did not start. Perhaps some missing dependencies. Need a couple of days to resolve. I will let you know. |
@robert-marik: Yeah, there are several changes that need to be accounted for to get things up and running. We need to get that documented. Note that there are some changes to |
f53e98e
to
b65fc96
Compare
Hello. I succeeded to switch branch and was able to test the patch. Thank you again for working on this. I have Europe/Prague timezone. I tried to edit open/close dates in HW sets editor. I can see correct times and days in local format. |
f9de8e0
to
1fbb938
Compare
I'm still new to the new "asset build system". When I first tested this, I had not set the timezone for the course in the test course I was using nor in After setting However, intentionally setting a course to a different timezone than the local timezone, which is a use case my server supports - it becomes very confusing to use the date-picker, as the tool is certainly using the local timezone, while the input box/stored setting is using the course time-zone. |
I am not sure what you are saying. It seems to be working correctly for me. If the course default is the site default in |
Also, you should not need to separately run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what to recommend to fix this, but this code behaves very problematically if a user needs to change a date in a course whose timezone is different from his local (the browsers) timezone.
For example, set a course to a time-zone different that your and then edit a date by changing the values of the minutes by a small shift. After saving the change - the hour will be changed. (Pressing tab has essentially the same effect.) It seems that this is a result of the "text value" being parsed in the browser's local timezone and then converted into the course time-zone.
Apparently, flatpickr is known to be quite problematic in terms of time-zone support.
See:
I was running
|
Here is a movie of the unusual behavior when the browser timezone and course timezone are different. Timezone-issue.mp4 |
I can't see your video. It seems to be corrupt. Although, now I see your problem. If you open the time picker and select a time, that time is not what ends up in the input. It gets adjusted by the time zone. I will see what I can do about that. |
By the way, it isn't flatpickr that is the problem. flatpickr is already in use in the develop branch, and this does not happen there. It is the locale time formatting that I added in this pull request that is the problem. |
@taniwallach: You never answered my question about the |
@taniwallach: As to running |
I sent a response inside #1615 (comment) . |
@taniwallach: Sorry, I missed that. Thanks. I will add the |
You should note that this only supports the languages that we have translations for. So this does not support Arabic at this point. Each language that we support will now need a format added to datepicker.js and problemsetlist.js. All of our current languages already have formats in those files. The formats should be chosen to be consistent with the formats that perl's DateTime::Locale pacakge uses. |
@taniwallach: So have you had a chance to test this again since I fixed everything? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In terms of the functionality of the new code to modify dates - everything I tested works properly now. I tested in Hebrew for the various places where a set deadline can be edited for all users or a specific user.
The change to use dir="ltr"
certainly makes the date+time input boxes behave more conveniently for Hebrew courses, but the formatting is not fully consistent. I think that for the sake of consistency the places in the instructor tools put the date+time as a fixed string (ex. the table in the list of sets in the set editor) should also have dir="ltr"
applied to them. This is already the case in the table of sets assigned to a user ("UserDetail-date-table") for the class-wide fixed date.
If you do make that change - would you also try to force the "Set name" fields to also use dir="ltr"
as when there are spaces in the set name, and a RTL language is used the name gets garbled by the RTL direction.
@@ -63,7 +63,8 @@ Arabic ("ar") trigger the RTL direction setting. | |||
=cut | |||
|
|||
sub get_lang_and_dir { | |||
my $lang = shift; | |||
# en_us, fr_CA, etc., are not valid html language codes. They should be en-us, fr-CA, etc. | |||
my $lang = shift =~ s/_/-/gr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here
@@ -112,7 +113,8 @@ In some cases, the return result is empty. | |||
sub get_problem_lang_and_dir { | |||
my $pg_flags = shift; | |||
my $requested_mode = shift; | |||
my $lang = shift; | |||
# en_us, fr_CA, etc., are not valid html language codes. They sould be en-us, fr-CA, etc. | |||
my $lang = shift =~ s/_/-/gr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here
@@ -26,23 +44,83 @@ | |||
for (const rule of groupRules) { | |||
const orig_value = rule.value; | |||
|
|||
flatpickr(rule.parentNode, { | |||
luxon.Settings.defaultLocale = rule.dataset.locale?.replaceAll(/_/g, '-') ?? 'en'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the replaceAll
needed here after the change to the PO file names made in #1632 ?
// Initialize the date/time picker for the import form. | ||
const importDateShift = document.getElementById('import_date_shift'); | ||
if (importDateShift) { | ||
flatpickr(importDateShift.parentNode, { | ||
|
||
luxon.Settings.defaultLocale = importDateShift.dataset.locale?.replaceAll(/_/g, '-') ?? 'en'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here
I see. I missed adding the Yeah, the underscore to space substitutions aren't needed anymore. This pull request came before the one that changed the locale file names, and so that was needed. I will remove that. I can look into adding |
I will deal with the set names in a separate pull request. That is unrelated to this one. Although, I would like to talk to you in general about this. Is there any possibility that you could meet via zoom sometime today? I can meet anytime. I was looking into this, and it may be that instead of adding |
Looks like @robert-marik approved this. @drgrice1 let's merge after the conflicts. |
Working on it now. |
Instead of formatting the unix timestamp for display in the inputs for dates in the instructor tools, just use the unix timestamp in those inputs. The flatpickr javascript now hides those inputs and adds an input that the user actually sees. That input contains a localized time string that is formatted for the locale (language) of the course via native javascript's Intl.DateTimeFormat. The flatpickr javascript takes care of updating the value of the hidden input with a unix timestamp as the user changes the visible input. To make this work well the dates that are only used for display are formatted with a different approach by Perl. The DateTime format_cldr is used for this instead of strftime. This allows for the use of the DateTime::Locale methods which provides uniform formatting for different languages. A special case is added to the lib/WeBWorK/Utils.pm formatDateTime function to handle this. To be precise, javascript uses Intl.DateTimeFormat with the options `{ dateStyle: 'short', timeStyle: 'short' }`, and perl uses the formatting string returned by `$dt->locale->datetime_format_short`. This also makes things work cleaner in the way that the server handles dates because you don't need to worry about parsing a date string back to a unix timestamp. For most languages the perl DateTime::Locale formatting and javascript Intl.DateTimeFormat formatting are the same. Unfortunately, for a few languages Perl's DateTime::Locale formatting is not correct. This can be seen when editing a problem set values for a user. The user values are formatted by javascript, and the class values by perl. The languages that seem to have problems here are any of the Asian languages. In Korean javascript gives `22. 3. 16. 오전 12:00` and perl gives `23. 3. 16. AM 12:00`. Clearly perl is not properly translating the AM/PM part. For zh_CN javascript gives `2022/3/16 00:00` and perl gives `2022/3/16 上午12:00`. Javscript gives a 24 hour time, and perl uses a 12 hour time. For zh_hk javascript gives `16/3/2022 上午12:00` and perl gives `2022/3/16 上午12:00`. So perl does not seem to use the correct ordering of the year, month, and day for that locale. Of course this means that the old strftime format `%m/%d/%Y at %I:%M%P` is not used for set dates anymore. For English the CLDR format returned by `datetime_format_short` that is now used is `M/d/yy, h:mm a`. This means instead of `03/16/2022 at 12:00am` you get `3/16/22, 12:00 AM`. I would prefer `03/16/2022, 12:00 AM`, but that is what our locale gives consistently for javascript and perl. So it is probably best to go with the standard. Note that the old format is still used for set export and import files. In fact that is the only place that the parseDateTime method is still used. It is used there to ensure that the correct timezone is set for the saved dates. Note that the `useDateTimePicker` option has been removed. That could be re-implemented if desired, but it would be a bit tedious to do so. The problem is that the date/time picker does not format and parse dates, but if that option is disabled then you would need to. I don't really see the need for that option anymore though. There is a minor change in the lib/WeBWorK/Utils/LanguageAndDirection.pm file. That was using the po filenames directly for the html `lang` attribute. Those filenames use underscores which are not valid for the `lang` attribute. So the underscores are translated to dashes.
the browser's timezone and the course timezone.
instead of using javascript Intl formats for date/times, use format strings chosen to match the perl DateTime::Locale formats. We have to use formats in any case to correctly parse strings back to a unix timestamp. So we might as well use them both ways, and make the perl display match that of the javascript better. There is only one exception. That is for the Korean language. The perl DateTime::Locale does not translate the AM/PM meridian, and the javascript does. There isn't much that can be done about that except for fixing the perl DateTime::Locale data.
accessibility purposes.
That is not needed anymore now that they have been renamed. Add `dir="ltr"` to the dates in the ProblemSetList.pm main table.
This is now updated. |
Instead of formatting the unix timestamp for display in the inputs for dates in the instructor tools, just use the unix timestamp in those inputs. The flatpickr javascript now hides those inputs and adds an input that the user actually sees. That input contains a localized time string that is formatted for the locale (language) of the course via native javascript's Intl.DateTimeFormat. The flatpickr javascript takes care of updating the value of the hidden input with a unix timestamp as the user changes the visible input.
To make this work well the dates that are only used for display are formatted with a different approach by Perl. The DateTime format_cldr is used for this instead of strftime. This allows for the use of the DateTime::Locale methods which provides uniform formatting for different languages. A special case is added to the lib/WeBWorK/Utils.pm formatDateTime function to handle this.
To be precise, javascript uses Intl.DateTimeFormat with the options
{ dateStyle: 'short', timeStyle: 'short' }
, and perl uses the formatting string returned by$dt->locale->datetime_format_short
.Edit: Now the javascript instead uses the
luxon
date time library with carefully chosen formats that match the perl formats.This also makes things work cleaner in the way that the server handles dates because you don't need to worry about parsing a date string back to a unix timestamp.
For most languages the perl DateTime::Locale formatting and javascript formatting are the same. Unfortunately, for a few languages Perl's DateTime::Locale formatting is not correct. This can be seen when editing a problem set values for a user. The user values are formatted by javascript, and the class values by perl. The languages that seem to have problems here are any of the Asian languages. In Korean javascript gives
22. 3. 16. 오전 12:00
and perl gives22. 3. 16. AM 12:00
. Clearly perl is not properly translating the AM/PM part. For zh_CN javascript gives2022/3/16 00:00
and perl gives2022/3/16 上午12:00
. Javscript gives a 24 hour time, and perl uses a 12 hour time. For zh_hk javascript gives16/3/2022 上午12:00
and perl gives2022/3/16 上午12:00
. So perl does not seem to use the correct ordering of the year, month, and day for that locale.Edit: With the recent changes to this pull request, only the Korean language still has differences between the perl and javascript.
Of course this means that the old strftime format
%m/%d/%Y at %I:%M%P
is not used for set dates anymore. For English the CLDR format returned bydatetime_format_short
that is now used isM/d/yy, h:mm a
. This means instead of03/16/2022 at 12:00am
you get3/16/22, 12:00 AM
. I would prefer03/16/2022, 12:00 AM
, but that is what our locale gives consistently for javascript and perl. So it is probably best to go with the standard.Note that the old format is still used for set export and import files. In fact that is the only place that the parseDateTime method is still used. It is used there to ensure that the correct timezone is set for the saved dates.
Note that the
useDateTimePicker
option has been removed. That could be re-implemented if desired, but it would be a bit tedious to do so. The problem is that the date/time picker does not format and parse dates, but if that option is disabled then you would need to. I don't really see the need for that option anymore though.There is a minor change in the lib/WeBWorK/Utils/LanguageAndDirection.pm file. That was using the po filenames directly for the html
lang
attribute. Those filenames use underscores which are not valid for thelang
attribute. So the underscores are translated to dashes.Edit: The above comment is no longer valid, and was removed from the code.
Note that this pull request replaces #1333, and it what I meant in the discussion there as to the correct way to do this.