Skip to content

Commit

Permalink
Merge pull request #2258 from drgrice1/bugfix/datetrim
Browse files Browse the repository at this point in the history
Trim date strings for the date picker
  • Loading branch information
pstaabp authored Nov 20, 2023
2 parents f5e234a + 65f88a7 commit a11a2de
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 31 deletions.
19 changes: 12 additions & 7 deletions htdocs/js/DatePicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
'en-US': 'L/d/yy, h:mm a',
'cs-CZ': 'dd.LL.yy H:mm',
de: 'dd.LL.yy, HH:mm',
es: 'd/L/yy H:mm',
el: 'd/L/yy, h:mm a',
es: 'd/L/yy, H:mm',
'fr-CA': "yyyy-LL-dd HH 'h' mm",
fr: 'dd/LL/yyyy HH:mm',
'he-IL': 'd.L.yyyy, H:mm',
Expand Down Expand Up @@ -65,7 +66,10 @@
ariaDateFormat: datetimeFormats[luxon.Settings.defaultLocale],
defaultDate: orig_value,
defaultHour: 0,
locale: rule.dataset.locale ? rule.dataset.locale.substring(0, 2) : 'en',
locale:
luxon.Settings.defaultLocale.substring(0, 2) === 'el'
? 'gr'
: luxon.Settings.defaultLocale.substring(0, 2),
clickOpens: false,
disableMobile: true,
wrap: true,
Expand All @@ -87,8 +91,8 @@
const today = new Date();
// If there isn't a selected date, then use 12:00 am on the current date.
const selectedDate = fp.selectedDates[0] ?? new Date(new Date().toDateString());
selectedDate.setFullYear(today.getFullYear())
selectedDate.setMonth(today.getMonth())
selectedDate.setFullYear(today.getFullYear());
selectedDate.setMonth(today.getMonth());
selectedDate.setDate(today.getDate());
fp.setDate(selectedDate);
} else if (index === 1) {
Expand Down Expand Up @@ -120,7 +124,7 @@

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

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

return luxon.DateTime.fromMillis(date.getTime())
.toFormat(datetimeFormats[luxon.Settings.defaultLocale]);
return luxon.DateTime.fromMillis(date.getTime()).toFormat(
datetimeFormats[luxon.Settings.defaultLocale]
);
}
});

Expand Down
19 changes: 12 additions & 7 deletions htdocs/js/ProblemSetList/problemsetlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
'en-US': 'L/d/yy, h:mm a',
'cs-CZ': 'dd.LL.yy H:mm',
de: 'dd.LL.yy, HH:mm',
es: 'd/L/yy H:mm',
el: 'd/L/yy, h:mm a',
es: 'd/L/yy, H:mm',
'fr-CA': "yyyy-LL-dd HH 'h' mm",
fr: 'dd/LL/yyyy HH:mm',
'he-IL': 'd.L.yyyy, H:mm',
Expand Down Expand Up @@ -85,7 +86,10 @@
altFormat: datetimeFormats[luxon.Settings.defaultLocale],
ariaDateFormat: datetimeFormats[luxon.Settings.defaultLocale],
defaultHour: 0,
locale: importDateShift.dataset.locale ? importDateShift.dataset.locale.substring(0, 2) : 'en',
locale:
luxon.Settings.defaultLocale.substring(0, 2) === 'el'
? 'gr'
: luxon.Settings.defaultLocale.substring(0, 2),
clickOpens: false,
disableMobile: true,
wrap: true,
Expand All @@ -107,8 +111,8 @@
const today = new Date();
// If there isn't a selected date, then use 12:00 am on the current date.
const selectedDate = fp.selectedDates[0] ?? new Date(new Date().toDateString());
selectedDate.setFullYear(today.getFullYear())
selectedDate.setMonth(today.getMonth())
selectedDate.setFullYear(today.getFullYear());
selectedDate.setMonth(today.getMonth());
selectedDate.setDate(today.getDate());
fp.setDate(selectedDate);
} else if (index === 1) {
Expand All @@ -133,7 +137,7 @@

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

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

return luxon.DateTime.fromMillis(date.getTime())
.toFormat(datetimeFormats[luxon.Settings.defaultLocale]);
return luxon.DateTime.fromMillis(date.getTime()).toFormat(
datetimeFormats[luxon.Settings.defaultLocale]
);
}
});

Expand Down
19 changes: 11 additions & 8 deletions templates/ContentGenerator/Base/set_status.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
% && $set->reduced_scoring_date
% && $set->reduced_scoring_date != $set->due_date
% );
%
%
<div class="alert alert-info mb-3">
<%== $useReducedScoring ? '<p>' : '<p class="mb-0">' =%>
<%== $useReducedScoring ? '<p>' : '<p class="mb-0">' =%>
<strong>
% if (before($set->open_date)) {
<%= maketext('Set opens on [_1].', $c->formatDateTime($set->open_date)) %>
<%= maketext('Set opens on [_1].',
$c->formatDateTime($set->open_date, undef, $ce->{studentDateDisplayFormat})) %>
% } elsif ($useReducedScoring && before($set->reduced_scoring_date)) {
<%= maketext('Set is due on [_1].', $c->formatDateTime($set->reduced_scoring_date)) %>
<%= maketext('Set is due on [_1].',
$c->formatDateTime($set->reduced_scoring_date, undef, $ce->{studentDateDisplayFormat})) %>
% } elsif (before($set->due_date)) {
<%= maketext('Set closes on [_1].', $c->formatDateTime($set->due_date)) %>
<%= maketext('Set closes on [_1].',
$c->formatDateTime($set->due_date, undef, $ce->{studentDateDisplayFormat})) %>
% } else {
<%= maketext('Set is closed.') %>
% }
Expand All @@ -31,7 +34,7 @@
<%= maketext(
'After the due date this set enters a reduced scoring period until it closes on [_1]. All work '
. 'completed during the reduced scoring period counts for [_2]% of its value.',
$c->formatDateTime($set->due_date), $reducedScoringPerCent
$c->formatDateTime($set->due_date, undef, $ce->{studentDateDisplayFormat}), $reducedScoringPerCent
) =%>
% } elsif (between($reduced_scoring_date, $set->due_date)) {
<%= maketext(
Expand All @@ -42,8 +45,8 @@
<%= maketext(
'This set had a reduced scoring period that started on [_1] and ended on [_2]. '
. 'During that period all work counted for [_3]% of its value.',
$c->formatDateTime($reduced_scoring_date),
$c->formatDateTime($set->due_date),
$c->formatDateTime($reduced_scoring_date, undef, $ce->{studentDateDisplayFormat}),
$c->formatDateTime($set->due_date, undef, $ce->{studentDateDisplayFormat}),
$reducedScoringPerCent
) =%>
% }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
<%= javascript getAssetURL($ce, 'node_modules/luxon/build/global/luxon.min.js'), defer => undef =%>
<%= javascript getAssetURL($ce, 'node_modules/flatpickr/dist/flatpickr.min.js'), defer => undef =%>
% if ($ce->{language} !~ /^en/) {
<%= javascript
getAssetURL($ce, 'node_modules/flatpickr/dist/l10n/' . ($ce->{language} =~ s/^(..).*/$1/gr) . '.js'),
defer => undef =%>
<%= javascript getAssetURL(
$ce,
'node_modules/flatpickr/dist/l10n/'
. ($ce->{language} =~ /^el/ ? 'gr' : ($ce->{language} =~ s/^(..).*/$1/gr))
. '.js'
), defer => undef =%>
% }
<%= javascript getAssetURL($ce, 'node_modules/flatpickr/dist/plugins/confirmDate/confirmDate.js'),
defer => undef =%>
Expand Down
9 changes: 6 additions & 3 deletions templates/ContentGenerator/Instructor/ProblemSetList.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
<%= javascript getAssetURL($ce, 'node_modules/luxon/build/global/luxon.min.js'), defer => undef =%>
<%= javascript getAssetURL($ce, 'node_modules/flatpickr/dist/flatpickr.min.js'), defer => undef =%>
% if ($ce->{language} !~ /^en/) {
<%= javascript
getAssetURL($ce, 'node_modules/flatpickr/dist/l10n/' . ($ce->{language} =~ s/^(..).*/$1/gr) . '.js'),
defer => undef =%>
<%= javascript getAssetURL(
$ce,
'node_modules/flatpickr/dist/l10n/'
. ($ce->{language} =~ /^el/ ? 'gr' : ($ce->{language} =~ s/^(..).*/$1/gr))
. '.js'
), defer => undef =%>
% }
<%= javascript getAssetURL($ce, 'node_modules/flatpickr/dist/plugins/confirmDate/confirmDate.js'),
defer => undef =%>
Expand Down
9 changes: 6 additions & 3 deletions templates/ContentGenerator/Instructor/UserDetail.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
<%= javascript getAssetURL($ce, 'node_modules/luxon/build/global/luxon.min.js'), defer => undef =%>
<%= javascript getAssetURL($ce, 'node_modules/flatpickr/dist/flatpickr.min.js'), defer => undef =%>
% if ($ce->{language} !~ /^en/) {
<%= javascript
getAssetURL($ce, 'node_modules/flatpickr/dist/l10n/' . ($ce->{language} =~ s/^(..).*/$1/gr) . '.js'),
defer => undef =%>
<%= javascript getAssetURL(
$ce,
'node_modules/flatpickr/dist/l10n/'
. ($ce->{language} =~ /^el/ ? 'gr' : ($ce->{language} =~ s/^(..).*/$1/gr))
. '.js'
), defer => undef =%>
% }
<%= javascript getAssetURL($ce, 'node_modules/flatpickr/dist/plugins/confirmDate/confirmDate.js'),
defer => undef =%>
Expand Down

0 comments on commit a11a2de

Please sign in to comment.