Skip to content

Commit b6a18b1

Browse files
authored
Merge pull request #33688 from wlegolas/bugfix/issue-33248
Fix oldCreated date format when the created date was changed
2 parents e2d1443 + 326f61d commit b6a18b1

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

src/libs/ModifiedExpenseMessage.ts

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {format} from 'date-fns';
21
import Onyx from 'react-native-onyx';
32
import CONST from '@src/CONST';
43
import ONYXKEYS from '@src/ONYXKEYS';
54
import type {PolicyTags, ReportAction} from '@src/types/onyx';
65
import * as CurrencyUtils from './CurrencyUtils';
6+
import DateUtils from './DateUtils';
77
import * as Localize from './Localize';
88
import * as PolicyUtils from './PolicyUtils';
99
import * as ReportUtils from './ReportUtils';
@@ -145,13 +145,11 @@ function getForReportAction(reportAction: ReportAction): string {
145145
);
146146
}
147147

148-
const hasModifiedCreated = reportActionOriginalMessage && 'oldCreated' in reportActionOriginalMessage && 'created' in reportActionOriginalMessage;
149-
if (hasModifiedCreated) {
150-
// Take only the YYYY-MM-DD value as the original date includes timestamp
151-
let formattedOldCreated: Date | string = new Date(reportActionOriginalMessage?.oldCreated ? reportActionOriginalMessage.oldCreated : 0);
152-
formattedOldCreated = format(formattedOldCreated, CONST.DATE.FNS_FORMAT_STRING);
148+
if (reportActionOriginalMessage?.oldCreated && reportActionOriginalMessage?.created) {
149+
const formattedOldCreated = DateUtils.formatWithUTCTimeZone(reportActionOriginalMessage.oldCreated, CONST.DATE.FNS_FORMAT_STRING);
150+
153151
buildMessageFragmentForValue(
154-
reportActionOriginalMessage?.created ?? '',
152+
reportActionOriginalMessage.created,
155153
formattedOldCreated,
156154
Localize.translateLocal('common.date'),
157155
false,

tests/unit/ModifiedExpenseMessageTest.ts

+37
Original file line numberDiff line numberDiff line change
@@ -275,5 +275,42 @@ describe('ModifiedExpenseMessage', () => {
275275
expect(result).toEqual(expectedResult);
276276
});
277277
});
278+
279+
describe('when the created date is changed', () => {
280+
const reportAction = {
281+
...createRandomReportAction(1),
282+
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE,
283+
originalMessage: {
284+
created: '2023-12-27',
285+
oldCreated: '2023-12-26',
286+
},
287+
};
288+
289+
it('returns the correct text message', () => {
290+
const expectedResult = 'changed the date to 2023-12-27 (previously 2023-12-26).';
291+
292+
const result = ModifiedExpenseMessage.getForReportAction(reportAction);
293+
294+
expect(result).toEqual(expectedResult);
295+
});
296+
});
297+
298+
describe('when the created date was not changed', () => {
299+
const reportAction = {
300+
...createRandomReportAction(1),
301+
actionName: CONST.REPORT.ACTIONS.TYPE.MODIFIEDEXPENSE,
302+
originalMessage: {
303+
created: '2023-12-27',
304+
},
305+
};
306+
307+
it('returns the correct text message', () => {
308+
const expectedResult = 'changed the request';
309+
310+
const result = ModifiedExpenseMessage.getForReportAction(reportAction);
311+
312+
expect(result).toEqual(expectedResult);
313+
});
314+
});
278315
});
279316
});

0 commit comments

Comments
 (0)