Skip to content
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

Correct per diem time calculation for same-day expenses #56295

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/libs/PerDiemRequestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,19 @@ 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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us use the isSameDay of date-fns to avoid any unexpected edge cases.

Can you please remove the comments too? The code looks self-explanatory.

Copy link
Contributor Author

@Shahidullah-Muffakir Shahidullah-Muffakir Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, Updated.


if (isSameDay) {
// If same day, just calculate the direct hour difference
const hourDiff = differenceInMinutes(endDate, startDate) / 60;
return {
firstDay: hourDiff,
tripDays: 0,
lastDay: undefined,
};
}

const firstDayDiff = differenceInMinutes(startOfDay(addDays(startDate, 1)), startDate);
const tripDaysDiff = differenceInDays(startOfDay(endDate), startOfDay(addDays(startDate, 1)));
const lastDayDiff = differenceInMinutes(endDate, startOfDay(endDate));
Expand Down
Loading