Skip to content

Commit

Permalink
Merge pull request #34784 from dukenv0307/fix/33814
Browse files Browse the repository at this point in the history
Format created of transaction with date time value if the created date is the current date
  • Loading branch information
deetergp authored Jan 29, 2024
2 parents 41dee31 + e3472ec commit 6198343
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
20 changes: 18 additions & 2 deletions src/libs/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,18 @@ function getMicroseconds(): number {
return Date.now() * CONST.MICROSECONDS_PER_MS;
}

function getDBTimeFromDate(date: Date): string {
return date.toISOString().replace('T', ' ').replace('Z', '');
}

/**
* Returns the current time in milliseconds in the format expected by the database
* Convert the given timestamp to the "yyyy-MM-dd HH:mm:ss" format, as expected by the database
*
* @param [timestamp] the given timestamp (if omitted, defaults to the current time)
*/
function getDBTime(timestamp: string | number = ''): string {
const datetime = timestamp ? new Date(timestamp) : new Date();
return datetime.toISOString().replace('T', ' ').replace('Z', '');
return getDBTimeFromDate(datetime);
}

/**
Expand Down Expand Up @@ -733,6 +739,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): string {
const now = new Date();
const createdDate = parse(created, CONST.DATE.FNS_FORMAT_STRING, now);
return isSameDay(createdDate, now) ? getDBTimeFromDate(now) : created;
}
/**
* Returns the last business day of given date month
*
Expand Down Expand Up @@ -796,6 +811,7 @@ const DateUtils = {
getWeekEndsOn,
isTimeAtLeastOneMinuteInFuture,
formatToSupportedTimezone,
enrichMoneyRequestTimestamp,
getLastBusinessDayOfMonth,
};

Expand Down
10 changes: 6 additions & 4 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,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 @@ -903,7 +904,7 @@ function createDistanceRequest(report, participant, comment, created, category,
comment,
amount,
currency,
created,
currentCreated,
merchant,
userAccountID,
currentUserEmail,
Expand All @@ -928,7 +929,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 @@ -1312,14 +1313,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 @@ -1342,7 +1344,7 @@ function requestMoney(
amount,
currency,
comment,
created,
created: currentCreated,
merchant,
iouReportID: iouReport.reportID,
chatReportID: chatReport.reportID,
Expand Down

0 comments on commit 6198343

Please sign in to comment.