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

Format created of transaction with date time value if the created date is the current date #34784

Merged
merged 12 commits into from
Jan 29, 2024
10 changes: 10 additions & 0 deletions src/libs/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,15 @@ function formatToSupportedTimezone(timezoneInput: Timezone): Timezone {
};
}

/**
* Return the date with full format if the created date is the current date.
* Otherwise return the created date.
*/
function enrichMoneyRequestTimestamp(created: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please state the return type explicitly

Copy link
Contributor Author

@dukenv0307 dukenv0307 Jan 19, 2024

Choose a reason for hiding this comment

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

@cubuspl42 I updated the return type.

const currentTime = getDBTime();
return isSameDay(new Date(created), new Date(currentTime)) ? currentTime : created;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please test if it works when dropping the new Date(...) wrapping call

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IsSameDay only apply type number and Date.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, it does on 2.x indeed. I started a thread.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's some active discussion, but it won't be actionable for this PR. We're good here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we might have some timezone issues here...

getDBTime returns a time in UTC+0, but it is cleared of the timezone information... I don't think we should use its output at all for any time calculations.

I think what happens here is a round-trip of date conversions: local -> UTC -> local, or something like that...

We should do something like this if I'm not mistaken.

const now = new Date();
return isSameDate(new Date(created), now) ? getDBTimeFromDate(now) : created;

getDBTimeFromDate is the second half of getDBTime, extracted.

}

const DateUtils = {
formatToDayOfWeek,
formatToLongDateWithWeekday,
Expand Down Expand Up @@ -774,6 +783,7 @@ const DateUtils = {
getWeekEndsOn,
isTimeAtLeastOneMinuteInFuture,
formatToSupportedTimezone,
enrichMoneyRequestTimestamp,
};

export default DateUtils;
10 changes: 6 additions & 4 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,7 @@ function createDistanceRequest(report, participant, comment, created, category,
// If the report is an iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function
const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report);
const currentChatReport = isMoneyRequestReport ? ReportUtils.getReport(report.chatReportID) : report;
const currentCreated = DateUtils.enrichMoneyRequestTimestamp(created);

const optimisticReceipt = {
source: ReceiptGeneric,
Expand All @@ -881,7 +882,7 @@ function createDistanceRequest(report, participant, comment, created, category,
comment,
amount,
currency,
created,
currentCreated,
merchant,
userAccountID,
currentUserEmail,
Expand All @@ -906,7 +907,7 @@ function createDistanceRequest(report, participant, comment, created, category,
createdIOUReportActionID,
reportPreviewReportActionID: reportPreviewAction.reportActionID,
waypoints: JSON.stringify(validWaypoints),
created,
created: currentCreated,
category,
tag,
billable,
Expand Down Expand Up @@ -1260,14 +1261,15 @@ function requestMoney(
// If the report is iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function
const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report);
const currentChatReport = isMoneyRequestReport ? ReportUtils.getReport(report.chatReportID) : report;
const currentCreated = DateUtils.enrichMoneyRequestTimestamp(created);
const {payerAccountID, payerEmail, iouReport, chatReport, transaction, iouAction, createdChatReportActionID, createdIOUReportActionID, reportPreviewAction, onyxData} =
getMoneyRequestInformation(
currentChatReport,
participant,
comment,
amount,
currency,
created,
currentCreated,
merchant,
payeeAccountID,
payeeEmail,
Expand All @@ -1290,7 +1292,7 @@ function requestMoney(
amount,
currency,
comment,
created,
created: currentCreated,
merchant,
iouReportID: iouReport.reportID,
chatReportID: chatReport.reportID,
Expand Down
Loading