Skip to content

Commit

Permalink
#7997 - reset entered datetime value if time is not filled
Browse files Browse the repository at this point in the history
  • Loading branch information
novikov82 committed Apr 15, 2024
1 parent 3178248 commit bcba7d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/mask/mask_datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export class InputMaskDateTime extends InputMaskPattern {
if(date.length > 0) {
result.push(date.join("-"));
}
if(time.length > 0) {
if (time.length > 1) {
result.push(time.join(":"));
}
return result.join("T");
Expand Down Expand Up @@ -656,20 +656,26 @@ export class InputMaskDateTime extends InputMaskPattern {
public getUnmaskedValue(src: string): any {
let input = (src === undefined || src === null) ? "" : src.toString();
const inputParts = this.getParts(input);

this.setInputDateTimeData(inputParts);

const timeMarker = this.inputDateTimeData.filter(idtd => idtd.lexem.type === "timeMarker")[0]?.value.toLowerCase()[0];

const tempDateTime = this.createIDateTimeComposition();
let uncompleted = false;
this.inputDateTimeData.forEach(inputData => {
let str = inputData.value;
if (!str || str.length < inputData.lexem.count || inputData.lexem.type == "timeMarker") return undefined;
if (inputData.lexem.type == "timeMarker" || inputData.lexem.type == "separator") return;
if (!str || str.length < inputData.lexem.count) {
uncompleted = true;
return;
}
let value = parseInt(this.parseTwoDigitYear(inputData));
if (inputData.lexem.type == "hour" && timeMarker === "p" && value != this.twelve) value += this.twelve;
(tempDateTime as any)[inputData.lexem.type] = value;
});

return this.getISO_8601Format(tempDateTime);
return uncompleted ? "" : this.getISO_8601Format(tempDateTime);
}

public getMaskedValue(src: string) : string {
Expand Down
6 changes: 5 additions & 1 deletion tests/mask/mask_datetime_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ QUnit.test("get getMaskedValue value from ISO", function (assert) {
assert.equal(maskInstance.getMaskedValue("22:07"), "10:07");
});

QUnit.test("getISO_8601Format", function (assert) {
QUnit.test("getISO_8601Format getUnmaskedValue", function (assert) {
const maskInstance = new InputMaskDateTime();

maskInstance.pattern = "yyyy";
Expand All @@ -285,6 +285,10 @@ QUnit.test("getISO_8601Format", function (assert) {
assert.equal(maskInstance.getUnmaskedValue("12:45"), "12:45");
assert.equal(maskInstance.getUnmaskedValue("05:05"), "05:05");

maskInstance.pattern = "dd/mm/yyyy HH:MM";
assert.equal(maskInstance.getUnmaskedValue("24/07/1998 12:45"), "1998-07-24T12:45");
assert.equal(maskInstance.getUnmaskedValue("24/07/1998 HH:MM"), "");

maskInstance.pattern = "hh:MM tt";
assert.equal(maskInstance.getUnmaskedValue("12:45 pm"), "12:45");
assert.equal(maskInstance.getUnmaskedValue("05:05 am"), "05:05");
Expand Down

0 comments on commit bcba7d9

Please sign in to comment.