TP-22003|Kunal|ptp date fix (#224)
This commit is contained in:
committed by
GitHub Enterprise
parent
35ec183bd5
commit
ec238dec7b
@@ -6,6 +6,15 @@ export function isQuestionMandatory(question: QuestionV1): boolean {
|
||||
|
||||
export function validateInput(data: { answer: any, type: string }, allRules: any): boolean {
|
||||
let result = true
|
||||
const currentDate = new Date();
|
||||
const endOfDayDate = new Date(currentDate.getFullYear()
|
||||
,currentDate.getMonth()
|
||||
,currentDate.getDate()
|
||||
,23,59,59);
|
||||
const startOfDayDate = new Date(currentDate.getFullYear()
|
||||
,currentDate.getMonth()
|
||||
,currentDate.getDate()
|
||||
,0,0,0);
|
||||
if (allRules) {
|
||||
for (const ruleName of Object.keys(allRules)) {
|
||||
const rule = allRules[ruleName];
|
||||
@@ -21,15 +30,15 @@ export function validateInput(data: { answer: any, type: string }, allRules: any
|
||||
}
|
||||
|
||||
} else if (ruleName === Validators.MAX_TODAY && rule.value) {
|
||||
const unixAnswer = (new Date(data.answer.split("-").reverse().join("-"))).getTime()
|
||||
if (!(unixAnswer > 0 && unixAnswer <= Date.now())) {
|
||||
const unixAnswer = (new Date(data.answer.split("-").reverse().join("-"))).getTime();
|
||||
if (!(unixAnswer > 0 && unixAnswer <= endOfDayDate.getTime())) {
|
||||
result = rule.message;
|
||||
break;
|
||||
}
|
||||
|
||||
} else if (ruleName === Validators.MIN_TODAY && rule.value) {
|
||||
const unixAnswer = (new Date(data.answer.split("-").reverse().join("-"))).getTime()
|
||||
if(!(unixAnswer > 0 && unixAnswer >= Date.now())){
|
||||
if(!(unixAnswer > 0 && unixAnswer >= startOfDayDate.getTime())){
|
||||
result = rule.message;
|
||||
break;
|
||||
}
|
||||
@@ -44,4 +53,4 @@ export enum Validators {
|
||||
PATTERN = 'pattern',
|
||||
MAX_TODAY = 'maxToday',
|
||||
MIN_TODAY = 'minToday'
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user