Skip to content

Commit 4a7558c

Browse files
authored
Merge pull request #25476 from ShogunFire/fixWrongParseOfDate
Change the way we parse a date because it was converting in wrong timezone date
2 parents 2b2bafd + ffa7b08 commit 4a7558c

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/libs/ReportUtils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import _ from 'underscore';
2-
import {format} from 'date-fns';
2+
import {format, parseISO} from 'date-fns';
33
import Str from 'expensify-common/lib/str';
44
import lodashGet from 'lodash/get';
55
import lodashIntersection from 'lodash/intersection';
@@ -1370,7 +1370,7 @@ function getModifiedExpenseMessage(reportAction) {
13701370
const hasModifiedCreated = _.has(reportActionOriginalMessage, 'oldCreated') && _.has(reportActionOriginalMessage, 'created');
13711371
if (hasModifiedCreated) {
13721372
// Take only the YYYY-MM-DD value as the original date includes timestamp
1373-
let formattedOldCreated = new Date(reportActionOriginalMessage.oldCreated);
1373+
let formattedOldCreated = parseISO(reportActionOriginalMessage.oldCreated);
13741374
formattedOldCreated = format(formattedOldCreated, CONST.DATE.FNS_FORMAT_STRING);
13751375
return getProperSchemaForModifiedExpenseMessage(reportActionOriginalMessage.created, formattedOldCreated, 'date', false);
13761376
}

src/libs/TransactionUtils.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Onyx from 'react-native-onyx';
2-
import {format} from 'date-fns';
2+
import {format, parseISO, isValid} from 'date-fns';
33
import lodashGet from 'lodash/get';
44
import _ from 'underscore';
55
import CONST from '../CONST';
@@ -180,9 +180,11 @@ function getCurrency(transaction) {
180180
*/
181181
function getCreated(transaction) {
182182
const created = lodashGet(transaction, 'modifiedCreated', '') || lodashGet(transaction, 'created', '');
183-
if (created) {
184-
return format(new Date(created), CONST.DATE.FNS_FORMAT_STRING);
183+
const createdDate = parseISO(created);
184+
if (isValid(createdDate)) {
185+
return format(createdDate, CONST.DATE.FNS_FORMAT_STRING);
185186
}
187+
186188
return '';
187189
}
188190

0 commit comments

Comments
 (0)