Skip to content

Commit

Permalink
FIX: Date completion was failing in some cases (#2327)
Browse files Browse the repository at this point in the history
  • Loading branch information
JindrichSusen committed Dec 19, 2023
1 parent 43f0558 commit 3a85ac2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ export default class DateCompleter {
t.match(/^\d\d\d\s+\d\d\d\d$/) ||
t.match(/^\d\d\d\d?\s+\d\d$/) ||
t.match(/^\d\d\d\d\d\d\d\d\s+\d\d\d\d\d\d$/) ||
t.match(/^\d\d?\/\d\d?$/) ||
t.match(/^\d\d?\/\d\d?\s+\d\d?$/) ||
t.match(/^\d\d?\/\d\d?\s+\d\d\d\d$/) ||
t.match(/^\d\d?\/\d\d?\s+\d\d:\d\d$/) ||
t.match(/^\d\d?\/\d\d?\/\d\d?$/)
t.match(new RegExp("^\\d\\d?" + this.dateSeparator + "\\d?\\d?" + this.dateSeparator + "?\\d?\\d?\\d?\\d? *\\d?\\d?:?\\d?\\d?:?\\d?\\d?$"))
);
}

Expand All @@ -68,11 +64,7 @@ export default class DateCompleter {
t.match(/^\d\d\d\d\s+\d\d$/) ||
t.match(/^\d\d\d\d\d\d\d\d \d\d\d\d\d\d$/) ||
t.match(/^\d\d?$/) ||
t.match(new RegExp("^\\d\\d?\\" + this.dateSeparator + "\\d\\d?$")) ||
t.match(new RegExp("^\\d\\d?\\" + this.dateSeparator + "\\d\\d?\\s+\\d\\d?$")) ||
t.match(new RegExp("^\\d\\d?\\" + this.dateSeparator + "\\d\\d?\\s+\\d\\d\\d\\d$")) ||
t.match(new RegExp("^\\d\\d?\\" + this.dateSeparator + "\\d\\d?\\s+\\d\\d:\\d\\d$")) ||
t.match(new RegExp("^\\d\\d?\\" + this.dateSeparator + "\\d\\d?\\" + this.dateSeparator + "\\d\\d?$"))
t.match(new RegExp("^\\d\\d?" + this.dateSeparator + "\\d?\\d?" + this.dateSeparator + "?\\d?\\d?\\d?\\d? *\\d?\\d?:?\\d?\\d?:?\\d?\\d?$"))
);
}

Expand Down Expand Up @@ -149,7 +141,9 @@ export default class DateCompleter {
}

completeDateWithSeparators(incompleteDate: string): string {
const splitDate = incompleteDate.split(this.dateSeparator);
const splitDate = incompleteDate
.split(this.dateSeparator)
.filter(x => x !== "");
if (splitDate.length === 2) {
return incompleteDate + this.dateSeparator + this.timeNowFunc().year();
} else {
Expand Down
3 changes: 3 additions & 0 deletions frontend-html/src/tests/DateTimeCompleter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ test.each([
["129 12", "12/9/2020 12:00:00 PM"],
["1209 12", "12/9/2020 12:00:00 PM"],
["12092020 123020", "12/9/2020 12:30:20 PM"],
["6/5/2020", "6/5/2020"],
["6/5", "6/5/2020"],
["6/5 14", "6/5/2020 2:00:00 PM"],
["6/5 1430", "6/5/2020 2:30:00 PM"],
Expand All @@ -66,6 +67,8 @@ test.each([
["5 ", "05.12.2017"],
["05 ", "05.12.2017"],
["5.6", "05.06.2017"],
["5.6.", "05.06.2017"],
["5.6.2018", "05.06.2018"],
["5.6 14", "05.06.2017 14:00:00"],
["5.6 1430", "05.06.2017 14:30:00"],
["5.6 14:30", "05.06.2017 14:30:00"],
Expand Down

0 comments on commit 3a85ac2

Please sign in to comment.