Skip to content

Commit

Permalink
Merge pull request #25476 from ShogunFire/fixWrongParseOfDate
Browse files Browse the repository at this point in the history
Change the way we parse a date because it was converting in wrong timezone date
  • Loading branch information
mountiny authored Aug 21, 2023
2 parents 2b2bafd + ffa7b08 commit 4a7558c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'underscore';
import {format} from 'date-fns';
import {format, parseISO} from 'date-fns';
import Str from 'expensify-common/lib/str';
import lodashGet from 'lodash/get';
import lodashIntersection from 'lodash/intersection';
Expand Down Expand Up @@ -1370,7 +1370,7 @@ function getModifiedExpenseMessage(reportAction) {
const hasModifiedCreated = _.has(reportActionOriginalMessage, 'oldCreated') && _.has(reportActionOriginalMessage, 'created');
if (hasModifiedCreated) {
// Take only the YYYY-MM-DD value as the original date includes timestamp
let formattedOldCreated = new Date(reportActionOriginalMessage.oldCreated);
let formattedOldCreated = parseISO(reportActionOriginalMessage.oldCreated);
formattedOldCreated = format(formattedOldCreated, CONST.DATE.FNS_FORMAT_STRING);
return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.created, formattedOldCreated, 'date', false);
}
Expand Down
8 changes: 5 additions & 3 deletions src/libs/TransactionUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Onyx from 'react-native-onyx';
import {format} from 'date-fns';
import {format, parseISO, isValid} from 'date-fns';
import lodashGet from 'lodash/get';
import _ from 'underscore';
import CONST from '../CONST';
Expand Down Expand Up @@ -180,9 +180,11 @@ function getCurrency(transaction) {
*/
function getCreated(transaction) {
const created = lodashGet(transaction, 'modifiedCreated', '') || lodashGet(transaction, 'created', '');
if (created) {
return format(new Date(created), CONST.DATE.FNS_FORMAT_STRING);
const createdDate = parseISO(created);
if (isValid(createdDate)) {
return format(createdDate, CONST.DATE.FNS_FORMAT_STRING);
}

return '';
}

Expand Down

0 comments on commit 4a7558c

Please sign in to comment.