Skip to content

Commit 0d9f5e2

Browse files
authored
Merge pull request #2262 from drgrice1/bugfix/datetrim-hotfix
Trim date strings for the date picker and such (hotfix of #2258)
2 parents dec3933 + 8484570 commit 0d9f5e2

6 files changed

Lines changed: 53 additions & 31 deletions

File tree

htdocs/js/DatePicker/datepicker.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
'en-US': 'L/d/yy, h:mm a',
88
'cs-CZ': 'dd.LL.yy H:mm',
99
de: 'dd.LL.yy, HH:mm',
10-
es: 'd/L/yy H:mm',
10+
el: 'd/L/yy, h:mm a',
11+
es: 'd/L/yy, H:mm',
1112
'fr-CA': "yyyy-LL-dd HH 'h' mm",
1213
fr: 'dd/LL/yyyy HH:mm',
1314
'he-IL': 'd.L.yyyy, H:mm',
@@ -65,7 +66,10 @@
6566
ariaDateFormat: datetimeFormats[luxon.Settings.defaultLocale],
6667
defaultDate: orig_value,
6768
defaultHour: 0,
68-
locale: rule.dataset.locale ? rule.dataset.locale.substring(0, 2) : 'en',
69+
locale:
70+
luxon.Settings.defaultLocale.substring(0, 2) === 'el'
71+
? 'gr'
72+
: luxon.Settings.defaultLocale.substring(0, 2),
6973
clickOpens: false,
7074
disableMobile: true,
7175
wrap: true,
@@ -87,8 +91,8 @@
8791
const today = new Date();
8892
// If there isn't a selected date, then use 12:00 am on the current date.
8993
const selectedDate = fp.selectedDates[0] ?? new Date(new Date().toDateString());
90-
selectedDate.setFullYear(today.getFullYear())
91-
selectedDate.setMonth(today.getMonth())
94+
selectedDate.setFullYear(today.getFullYear());
95+
selectedDate.setMonth(today.getMonth());
9296
selectedDate.setDate(today.getDate());
9397
fp.setDate(selectedDate);
9498
} else if (index === 1) {
@@ -120,7 +124,7 @@
120124

121125
// Next attempt to parse the datestr with the current format. This should not be adjusted. It is
122126
// for display only.
123-
const date = luxon.DateTime.fromFormat(datestr, format);
127+
const date = luxon.DateTime.fromFormat(datestr.replaceAll(/\u202F/g, ' ').trim(), format);
124128
if (date.isValid) return date.toJSDate();
125129

126130
// Finally, fall back to the previous value in the original input if that failed. This is the case
@@ -136,8 +140,9 @@
136140
// timezone of the course.
137141
if (format === 'U') return (date.getTime() + timezoneAdjustment) / 1000;
138142

139-
return luxon.DateTime.fromMillis(date.getTime())
140-
.toFormat(datetimeFormats[luxon.Settings.defaultLocale]);
143+
return luxon.DateTime.fromMillis(date.getTime()).toFormat(
144+
datetimeFormats[luxon.Settings.defaultLocale]
145+
);
141146
}
142147
});
143148

htdocs/js/ProblemSetList/problemsetlist.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
'en-US': 'L/d/yy, h:mm a',
5050
'cs-CZ': 'dd.LL.yy H:mm',
5151
de: 'dd.LL.yy, HH:mm',
52-
es: 'd/L/yy H:mm',
52+
el: 'd/L/yy, h:mm a',
53+
es: 'd/L/yy, H:mm',
5354
'fr-CA': "yyyy-LL-dd HH 'h' mm",
5455
fr: 'dd/LL/yyyy HH:mm',
5556
'he-IL': 'd.L.yyyy, H:mm',
@@ -85,7 +86,10 @@
8586
altFormat: datetimeFormats[luxon.Settings.defaultLocale],
8687
ariaDateFormat: datetimeFormats[luxon.Settings.defaultLocale],
8788
defaultHour: 0,
88-
locale: importDateShift.dataset.locale ? importDateShift.dataset.locale.substring(0, 2) : 'en',
89+
locale:
90+
luxon.Settings.defaultLocale.substring(0, 2) === 'el'
91+
? 'gr'
92+
: luxon.Settings.defaultLocale.substring(0, 2),
8993
clickOpens: false,
9094
disableMobile: true,
9195
wrap: true,
@@ -107,8 +111,8 @@
107111
const today = new Date();
108112
// If there isn't a selected date, then use 12:00 am on the current date.
109113
const selectedDate = fp.selectedDates[0] ?? new Date(new Date().toDateString());
110-
selectedDate.setFullYear(today.getFullYear())
111-
selectedDate.setMonth(today.getMonth())
114+
selectedDate.setFullYear(today.getFullYear());
115+
selectedDate.setMonth(today.getMonth());
112116
selectedDate.setDate(today.getDate());
113117
fp.setDate(selectedDate);
114118
} else if (index === 1) {
@@ -133,7 +137,7 @@
133137

134138
// Next attempt to parse the datestr with the current format. This should not be adjusted. It is
135139
// for display only.
136-
const date = luxon.DateTime.fromFormat(datestr, format);
140+
const date = luxon.DateTime.fromFormat(datestr.replaceAll(/\u202F/g, ' ').trim(), format);
137141
if (date.isValid) return date.toJSDate();
138142

139143
// Finally, fall back to the previous value in the original input if that failed. This is the case
@@ -149,8 +153,9 @@
149153
// timezone of the course.
150154
if (format === 'U') return (date.getTime() + timezoneAdjustment) / 1000;
151155

152-
return luxon.DateTime.fromMillis(date.getTime())
153-
.toFormat(datetimeFormats[luxon.Settings.defaultLocale]);
156+
return luxon.DateTime.fromMillis(date.getTime()).toFormat(
157+
datetimeFormats[luxon.Settings.defaultLocale]
158+
);
154159
}
155160
});
156161

templates/ContentGenerator/Base/set_status.html.ep

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66
% && $set->reduced_scoring_date
77
% && $set->reduced_scoring_date != $set->due_date
88
% );
9-
%
9+
%
1010
<div class="alert alert-info mb-3">
11-
<%== $useReducedScoring ? '<p>' : '<p class="mb-0">' =%>
11+
<%== $useReducedScoring ? '<p>' : '<p class="mb-0">' =%>
1212
<strong>
1313
% if (before($set->open_date)) {
14-
<%= maketext('Set opens on [_1].', $c->formatDateTime($set->open_date)) %>
14+
<%= maketext('Set opens on [_1].',
15+
$c->formatDateTime($set->open_date, undef, $ce->{studentDateDisplayFormat})) %>
1516
% } elsif ($useReducedScoring && before($set->reduced_scoring_date)) {
16-
<%= maketext('Set is due on [_1].', $c->formatDateTime($set->reduced_scoring_date)) %>
17+
<%= maketext('Set is due on [_1].',
18+
$c->formatDateTime($set->reduced_scoring_date, undef, $ce->{studentDateDisplayFormat})) %>
1719
% } elsif (before($set->due_date)) {
18-
<%= maketext('Set closes on [_1].', $c->formatDateTime($set->due_date)) %>
20+
<%= maketext('Set closes on [_1].',
21+
$c->formatDateTime($set->due_date, undef, $ce->{studentDateDisplayFormat})) %>
1922
% } else {
2023
<%= maketext('Set is closed.') %>
2124
% }
@@ -31,7 +34,7 @@
3134
<%= maketext(
3235
'After the due date this set enters a reduced scoring period until it closes on [_1]. All work '
3336
. 'completed during the reduced scoring period counts for [_2]% of its value.',
34-
$c->formatDateTime($set->due_date), $reducedScoringPerCent
37+
$c->formatDateTime($set->due_date, undef, $ce->{studentDateDisplayFormat}), $reducedScoringPerCent
3538
) =%>
3639
% } elsif (between($reduced_scoring_date, $set->due_date)) {
3740
<%= maketext(
@@ -42,8 +45,8 @@
4245
<%= maketext(
4346
'This set had a reduced scoring period that started on [_1] and ended on [_2]. '
4447
. 'During that period all work counted for [_3]% of its value.',
45-
$c->formatDateTime($reduced_scoring_date),
46-
$c->formatDateTime($set->due_date),
48+
$c->formatDateTime($reduced_scoring_date, undef, $ce->{studentDateDisplayFormat}),
49+
$c->formatDateTime($set->due_date, undef, $ce->{studentDateDisplayFormat}),
4750
$reducedScoringPerCent
4851
) =%>
4952
% }

templates/ContentGenerator/Instructor/ProblemSetDetail.html.ep

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
<%= javascript getAssetURL($ce, 'node_modules/luxon/build/global/luxon.min.js'), defer => undef =%>
1212
<%= javascript getAssetURL($ce, 'node_modules/flatpickr/dist/flatpickr.min.js'), defer => undef =%>
1313
% if ($ce->{language} !~ /^en/) {
14-
<%= javascript
15-
getAssetURL($ce, 'node_modules/flatpickr/dist/l10n/' . ($ce->{language} =~ s/^(..).*/$1/gr) . '.js'),
16-
defer => undef =%>
14+
<%= javascript getAssetURL(
15+
$ce,
16+
'node_modules/flatpickr/dist/l10n/'
17+
. ($ce->{language} =~ /^el/ ? 'gr' : ($ce->{language} =~ s/^(..).*/$1/gr))
18+
. '.js'
19+
), defer => undef =%>
1720
% }
1821
<%= javascript getAssetURL($ce, 'node_modules/flatpickr/dist/plugins/confirmDate/confirmDate.js'),
1922
defer => undef =%>

templates/ContentGenerator/Instructor/ProblemSetList.html.ep

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
<%= javascript getAssetURL($ce, 'node_modules/luxon/build/global/luxon.min.js'), defer => undef =%>
1010
<%= javascript getAssetURL($ce, 'node_modules/flatpickr/dist/flatpickr.min.js'), defer => undef =%>
1111
% if ($ce->{language} !~ /^en/) {
12-
<%= javascript
13-
getAssetURL($ce, 'node_modules/flatpickr/dist/l10n/' . ($ce->{language} =~ s/^(..).*/$1/gr) . '.js'),
14-
defer => undef =%>
12+
<%= javascript getAssetURL(
13+
$ce,
14+
'node_modules/flatpickr/dist/l10n/'
15+
. ($ce->{language} =~ /^el/ ? 'gr' : ($ce->{language} =~ s/^(..).*/$1/gr))
16+
. '.js'
17+
), defer => undef =%>
1518
% }
1619
<%= javascript getAssetURL($ce, 'node_modules/flatpickr/dist/plugins/confirmDate/confirmDate.js'),
1720
defer => undef =%>

templates/ContentGenerator/Instructor/UserDetail.html.ep

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@
99
<%= javascript getAssetURL($ce, 'node_modules/luxon/build/global/luxon.min.js'), defer => undef =%>
1010
<%= javascript getAssetURL($ce, 'node_modules/flatpickr/dist/flatpickr.min.js'), defer => undef =%>
1111
% if ($ce->{language} !~ /^en/) {
12-
<%= javascript
13-
getAssetURL($ce, 'node_modules/flatpickr/dist/l10n/' . ($ce->{language} =~ s/^(..).*/$1/gr) . '.js'),
14-
defer => undef =%>
12+
<%= javascript getAssetURL(
13+
$ce,
14+
'node_modules/flatpickr/dist/l10n/'
15+
. ($ce->{language} =~ /^el/ ? 'gr' : ($ce->{language} =~ s/^(..).*/$1/gr))
16+
. '.js'
17+
), defer => undef =%>
1518
% }
1619
<%= javascript getAssetURL($ce, 'node_modules/flatpickr/dist/plugins/confirmDate/confirmDate.js'),
1720
defer => undef =%>

0 commit comments

Comments
 (0)