Skip to content

Commit f02d2f7

Browse files
authored
Merge pull request #2944 from drgrice1/bugfix/datepicker
Fix a minor issue with the datepicker.
2 parents 07444a2 + df014ba commit f02d2f7

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

htdocs/js/DatePicker/datepicker.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,14 @@
119119
],
120120
onClick: (index, fp) => {
121121
if (index === 0) {
122-
const today = new Date();
123-
// If there isn't a selected date, then use 12:00 am on the current date.
124-
const selectedDate = fp.selectedDates[0] ?? new Date(new Date().toDateString());
125-
selectedDate.setFullYear(today.getFullYear());
126-
selectedDate.setMonth(today.getMonth());
127-
selectedDate.setDate(today.getDate());
128-
fp.setDate(selectedDate, true);
122+
// The initial date represents 12:00 am on the current date.
123+
const today = new Date(new Date().toDateString());
124+
if (fp.selectedDates[0]) {
125+
today.setHours(fp.selectedDates[0].getHours());
126+
today.setMinutes(fp.selectedDates[0].getMinutes());
127+
today.setSeconds(fp.selectedDates[0].getSeconds());
128+
}
129+
fp.setDate(today, true);
129130
} else if (index === 1) {
130131
fp.setDate(new Date(), true);
131132
}

htdocs/js/ProblemSetList/problemsetlist.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,14 @@
251251
],
252252
onClick: (index, fp) => {
253253
if (index === 0) {
254-
const today = new Date();
255-
// If there isn't a selected date, then use 12:00 am on the current date.
256-
const selectedDate = fp.selectedDates[0] ?? new Date(new Date().toDateString());
257-
selectedDate.setFullYear(today.getFullYear());
258-
selectedDate.setMonth(today.getMonth());
259-
selectedDate.setDate(today.getDate());
260-
fp.setDate(selectedDate);
254+
// The initial date represents 12:00 am on the current date.
255+
const today = new Date(new Date().toDateString());
256+
if (fp.selectedDates[0]) {
257+
today.setHours(fp.selectedDates[0].getHours());
258+
today.setMinutes(fp.selectedDates[0].getMinutes());
259+
today.setSeconds(fp.selectedDates[0].getSeconds());
260+
}
261+
fp.setDate(today, true);
261262
} else if (index === 1) {
262263
fp.setDate(new Date());
263264
}

0 commit comments

Comments
 (0)