I think you should tell us the conditions in details so that we could help you check the codes following the rules you defined.
Could you please specify the conditions so that we could understand the rules correctly?
Condition 1:Shift start time should be less than of end time.
Shift Start Time: 11: 00, Shift End Time should be later than 11:00, e.g. 15:00, correct?
Condition 2:Shift break times such asbreak1(start and end time), break2(start and end time), break3(start and end time).
start and end time should be following the same rule as Shift Time, correct?
Condition 3:Break1 start time should be less than ofshift end time
Since you use the 'less', which is similar to the Condition 1,
do you mean that the Break1 end time should be also
less than the shift end time?
Condition 4:Break2 start time should be less than ofbreak 1 end time
Shift Start Time: 11:00, Shift End Time: 15:00
Break1 Start Time: 13:30, Break1 End Time: 14:30, are suitable time period
How would you put the Break2 in above example?
Condition 5:Break3 start time should be less than ofbreak 2 end time. Withoutbreak2break3 timing will be considered as invali
You should also specify the condition for break3 with considering the comparison with Shift time period, Break1 time period and Break2 time period.
One point here is that the time will be invalid if any of previous time is invalid or missing, correct?
By the way, you could refactor the js code since you repeat too many time for comparison. Another improvement would be removing the 'true' or 'false' in if condition since the returned value of the function
is of type 'bool'.
For example,
//you could modify '== false' with a simple symbol '!'
if (shift.isValidate24HourTime(startTimeEl.val()) == false) {
startTimeEl.addClass("validate-time-invalid");
}
// as below
if (!shift.isValidate24HourTime(startTimeEl.val())) {
startTimeEl.addClass("validate-time-invalid");
}
// no need to compare true with true
if (shift.isValidate24HourTime(startTimeEl.val()) == true && shift.isValidate24HourTime(endTimeEl.val()) == true) {
......
}
// Try below codes
if (shift.isValidate24HourTime(startTimeEl.val()) && shift.isValidate24HourTime(endTimeEl.val())) {
......
}
Looking forward to your reply.
Best regards,
Sean
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
None
0 Points
7 Posts
How to validate shift timing from time and to time
Jan 22, 2021 12:48 PM|prasadr07|LINK
I am looking for a solutions to validate the shift timing in jquery
Condition 1: Shift start time should be less than of end time
Condition 2: Shift break times such as break1(start and end time), break2(start and end time), break3(start and end time).
Condition 3: Break1 start time should be less than of shift end time
Condition 4: Break2 start time should be less than of break 1 end time
Condition 5: Break3 start time should be less than of break 2 end time. Without break2 break3 timing will be considered as invalid.
I made the jsfiddle example here: https://jsfiddle.net/nmtx4pa8/2/
i made the logic...it was not working propertly, can you advice to solve the issue
Participant
1620 Points
927 Posts
Re: How to validate shift timing from time and to time
Jan 23, 2021 12:04 AM|PaulTheSmith|LINK
None
0 Points
7 Posts
Re: How to validate shift timing from time and to time
Jan 23, 2021 03:00 AM|prasadr07|LINK
Thanks for your reply,
I have updated the question.
Condition 3 - The break must be after the shift finishes????
The break time should be less than of shift end time.
Contributor
2840 Points
840 Posts
Re: How to validate shift timing from time and to time
Jan 25, 2021 08:39 AM|Sean Fang|LINK
Hi prasadr07,
I think you should tell us the conditions in details so that we could help you check the codes following the rules you defined.
Could you please specify the conditions so that we could understand the rules correctly?
Condition 1: Shift start time should be less than of end time.
Shift Start Time: 11: 00, Shift End Time should be later than 11:00, e.g. 15:00, correct?
Condition 2: Shift break times such as break1(start and end time), break2(start and end time), break3(start and end time).
start and end time should be following the same rule as Shift Time, correct?
Condition 3: Break1 start time should be less than of shift end time
Since you use the 'less', which is similar to the Condition 1, do you mean that the Break1 end time should be also less than the shift end time?
Condition 4: Break2 start time should be less than of break 1 end time
Shift Start Time: 11:00, Shift End Time: 15:00
Break1 Start Time: 13:30, Break1 End Time: 14:30, are suitable time period
How would you put the Break2 in above example?
Condition 5: Break3 start time should be less than of break 2 end time. Without break2 break3 timing will be considered as invali
You should also specify the condition for break3 with considering the comparison with Shift time period, Break1 time period and Break2 time period.
One point here is that the time will be invalid if any of previous time is invalid or missing, correct?
By the way, you could refactor the js code since you repeat too many time for comparison. Another improvement would be removing the 'true' or 'false' in if condition since the returned value of the function is of type 'bool'.
For example,
Looking forward to your reply.
Best regards,
Sean