-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[$250] Per diem - Time summary on the confirmation page is incorrect #55449
Comments
Triggered auto assignment to @RachCHopkins ( |
ProposalPlease re-state the problem that we are trying to solve in this issue.When a user creates a per diem expense for the same day (like 8:00 AM to 10:00 AM), the app shows wrong time calculations. Instead of showing 2 hours, it shows "First day: 16.00 hours", "Trip: 1 full day", and "Last day: 10.00 hours". What is the root cause of that problem?The time calculation code doesn't check if the start and end dates are on the same day. It always tries to split the time into first day, trip days, and last day, even when everything happens on one day. This causes wrong calculations for same-day expenses. What changes do you think we should make in order to solve the problem?Add a check at the start of the calculation to see if start and end dates are on the same day App/src/libs/PerDiemRequestUtils.ts Line 257 in 64ed6a5
modify it as: function getTimeDifferenceIntervals(transaction: OnyxEntry<Transaction>) {
const customUnitRateDate = transaction?.comment?.customUnit?.attributes?.dates ?? {start: '', end: ''};
const startDate = new Date(customUnitRateDate.start);
const endDate = new Date(customUnitRateDate.end);
+ // Check if start and end dates are on the same day
+ const isSameDay = startOfDay(startDate).getTime() === startOfDay(endDate).getTime();
+
+ if (isSameDay) {
+ // If same day, just calculate the direct hour difference
+ const hourDiff = (differenceInMinutes(endDate, startDate) / 60).toFixed(2);
+ return {
+ firstDay: hourDiff,
+ tripDays: 0,
+ lastDay: undefined,
+ };
+ }
// Original logic for multi-day calculations
const firstDayDiff = differenceInMinutes(startOfDay(addDays(startDate, 1)), startDate);
const tripDaysDiff = differenceInDays(startOfDay(endDate), startOfDay(addDays(startDate, 1)));
const lastDayDiff = differenceInMinutes(endDate, startOfDay(endDate));
return {
firstDay: firstDayDiff === 1440 ? undefined : (firstDayDiff / 60).toFixed(2),
tripDays: firstDayDiff === 1440 ? tripDaysDiff + 1 : tripDaysDiff,
lastDay: lastDayDiff === 0 ? undefined : (lastDayDiff / 60).toFixed(2),
};
} What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?NA What alternative solutions did you explore? (Optional)NA Screen.Recording.2025-01-18.at.8.18.54.PM.mov |
ProposalPlease re-state the problem that we are trying to solve in this issue.After turning on the Make or track payments,the BA flow opens on the page where it was left What is the root cause of that problem?The function assumes startDate and endDate always span multiple days. App/src/libs/PerDiemRequestUtils.ts Lines 257 to 269 in 850c339
Example: Given startDate = '2025-01-16T08:00:00' and endDate = '2025-01-16T18:00:00' const firstDayDiff = differenceInMinutes(startOfDay(addDays(startDate, 1)), startDate); // Incorrectly calculates next day
const tripDaysDiff = differenceInDays(startOfDay(endDate), startOfDay(addDays(startDate, 1))); // Returns negative or invalid
const lastDayDiff = differenceInMinutes(endDate, startOfDay(endDate)); // Processes last day even for same-day trips What changes do you think we should make in order to solve the problem?To fix this issue, we need to check if startDate and endDate are on the same day at the start of the function. If they are, directly calculate the total time difference as firstDay and set tripDays and lastDay to undefined. import {..., isSameDay, ...} from 'date-fns'; function getTimeDifferenceIntervals(transaction: OnyxEntry<Transaction>) {
const customUnitRateDate = transaction?.comment?.customUnit?.attributes?.dates ?? {start: '', end: ''};
const startDate = new Date(customUnitRateDate.start);
const endDate = new Date(customUnitRateDate.end);
// Check if startDate and endDate are on the same day
if (isSameDay(startDate, endDate)) { // add this line
const totalMinutes = differenceInMinutes(endDate, startDate); // add this line
return { // add this line
firstDay: totalMinutes / 60, // add this line
tripDays: undefined, // add this line
lastDay: undefined, // add this line
}; // add this line
} // add this line
// If not on the same day, calculate intervals
const firstDayDiff = differenceInMinutes(startOfDay(addDays(startDate, 1)), startDate);
const tripDaysDiff = differenceInDays(startOfDay(endDate), startOfDay(addDays(startDate, 1)));
const lastDayDiff = differenceInMinutes(endDate, startOfDay(endDate));
return {
firstDay: firstDayDiff === 1440 ? undefined : firstDayDiff / 60,
tripDays: firstDayDiff === 1440 ? tripDaysDiff + 1 : tripDaysDiff,
lastDay: lastDayDiff === 0 ? undefined : lastDayDiff / 60,
};
} POCWhat specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?Create unit test for case same day. What alternative solutions did you explore? (Optional)Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job. |
I don't appear to have Per Diems. I will have to assume they exist because we have two people above who can repro this. Update: Per Diem is behind a beta. |
Job added to Upwork: https://www.upwork.com/jobs/~021881825734850372345 |
Triggered auto assignment to Contributor-plus team member for initial proposal review - @c3024 ( |
@c3024, when you get a chance, could you please review the proposals? Thank you |
Thanks for the bump. Checking! |
@Shahidullah-Muffakir 's RCA and suggested fix in his proposal here looks good to me! 🎀 👀 🎀 C+ reviewed! |
Triggered auto assignment to @lakchote, see https://stackoverflow.com/c/expensify/questions/7972 for more details. |
@lakchote, @RachCHopkins, @c3024 Whoops! This issue is 2 days overdue. Let's get this updated quick! |
@lakchote a little bump on this:
Thanks. |
@lakchote, @RachCHopkins, @c3024 Eep! 4 days overdue now. Issues have feelings too... |
@lakchote @RachCHopkins @c3024 this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks! |
@lakchote, @RachCHopkins, @c3024 8 days overdue is a lot. Should this be a Weekly issue? If so, feel free to change it! |
@Shahidullah-Muffakir's proposal LGTM. |
📣 @Shahidullah-Muffakir You have been assigned to this job! |
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Version Number: 9.0.87-0
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: N/A
If this was caught during regression testing, add the test name, ID and link from TestRail: N/A
Email or phone of affected tester (no customers): [email protected]
Issue reported by: Applause - Internal Team
Action Performed:
Precondition:
Expected Result:
The time summary should be correct on the confirmation page
It should show "First Day: 2.00 hours" because the configured duration is only 2 hours (the same on OD)
Actual Result:
The time summary is wrong on the confirmation page
It shows "First day: 16.00 hours", "Trip: 1 full day", "Last day: 10.00 hours" when the configured duration is only 2 hours
On OD, it shows the correct summary which is "First Day: 2.00 hours"
Workaround:
Unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
Screenshots/Videos
Add any screenshot/video evidence
Bug6717376_1737187618758.bandicam_2025-01-18_15-35-42-986.mp4
View all open jobs on GitHub
Upwork Automation - Do Not Edit
Issue Owner
Current Issue Owner: @lakchoteThe text was updated successfully, but these errors were encountered: