-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(fix) O3-4286: Fix error when starting a visit immediately after ending one #2175
base: main
Are you sure you want to change the base?
Changes from 7 commits
bcae102
23e502d
111e603
f528fdd
8e35f04
3ea84ab
b02565b
52ef729
53a05e4
22caafa
747eee4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,8 +142,9 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({ | |
// Validates that the start time is not in the future | ||
const validateStartTime = (data: z.infer<typeof visitFormSchema>) => { | ||
const [visitStartHours, visitStartMinutes] = convertTime12to24(data.visitStartTime, data.visitStartTimeFormat); | ||
const visitStartDatetime = new Date(data.visitStartDate).setHours(visitStartHours, visitStartMinutes); | ||
return new Date(visitStartDatetime) <= new Date(); | ||
const visitStartDatetime = new Date(data.visitStartDate); | ||
visitStartDatetime.setHours(visitStartHours, visitStartMinutes, 0, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure that zeroing out seconds is always the right thing to do here. Can you explain why we're doing so? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Explanation of Validation LogicThis change only affects the comparison logic, not the datetime storage format.
Example Scenario
ScreenshotKey TakeawayZeroing out the seconds ensures that only the hours and minutes are considered during validation, avoiding errors caused by minor mismatches in time precision. This approach simplifies the logic and aligns it with user expectations. Let me know sir if you’d like further modifications! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "@ibacher sir, please correct me if I am wrong. Was I thinking in the wrong way (approach)?" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. So the limiting factor here is the time picker component? I guess that makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But, then, shouldn't we either zero out the seconds component when sending this to the backend or use the seconds (and milliseconds) from the current timestamp? Otherwise, we're effectively sending data the user didn't supply to the backend and that's what gets stored (not to mention, we have a similar validation check on the backend that might fail with a quick enough connection). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@ibacher Sir, I agree with your assessment. To elaborate:
This solution will prevent overlap errors while maintaining accurate visit timing records. |
||
return visitStartDatetime <= new Date(); | ||
}; | ||
|
||
const hadPreviousStopDateTime = Boolean(visitToEdit?.stopDatetime); | ||
|
@@ -449,6 +450,7 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({ | |
dayjs(visitStartDate).date(), | ||
hours, | ||
minutes, | ||
dayjs(visitStartDate).second(), | ||
), | ||
), | ||
), | ||
|
@@ -472,6 +474,7 @@ const StartVisitForm: React.FC<StartVisitFormProps> = ({ | |
dayjs(visitStopDate).date(), | ||
visitStopHours, | ||
visitStopMinutes, | ||
dayjs(visitStopDate).second(), | ||
), | ||
), | ||
); | ||
|
@@ -876,4 +879,4 @@ const VisitFormExtensionSlot: React.FC<VisitFormExtensionSlotProps> = React.memo | |
}, | ||
); | ||
|
||
export default StartVisitForm; | ||
export default StartVisitForm; | ||
ibacher marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we adding this import?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.