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
18 changes: 18 additions & 0 deletions src/libs/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,23 @@ function formatToSupportedTimezone(timezoneInput: Timezone): Timezone {
};
}

/**
* Returns the time in milliseconds of a date in the format expected by the database
Copy link
Contributor

Choose a reason for hiding this comment

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

Time in milliseconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated comment.

*/
function getDBTimeFromDate(date: Date): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Well, please use it inside getDBTime now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use getDBTimeFromDate in getDBTime.

return date.toISOString().replace('T', ' ').replace('Z', '');
}

/**
* Return the date with full format if the created date is the current date.
* Otherwise return the created date.
*/
function enrichMoneyRequestTimestamp(created: string): string {
const now = new Date();
const createdDate = parse(created, CONST.DATE.FNS_FORMAT_STRING, now);
return isSameDay(createdDate, now) ? getDBTimeFromDate(now) : created;
}

const DateUtils = {
formatToDayOfWeek,
formatToLongDateWithWeekday,
Expand Down Expand Up @@ -774,6 +791,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 @@ -1275,14 +1276,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 @@ -1305,7 +1307,7 @@ function requestMoney(
amount,
currency,
comment,
created,
created: currentCreated,
merchant,
iouReportID: iouReport.reportID,
chatReportID: chatReport.reportID,
Expand Down
Loading