Skip to content

Commit cb6e38d

Browse files
committed
fix: incorrect test case and function refactor
1 parent fbcff96 commit cb6e38d

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

packages/shared/src/utils/date/__tests__/date-time.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ describe('formatDate', () => {
7171
expect(DateTime.formatDate(date, date_format, true)).toEqual(moment(date).format(date_format));
7272
});
7373

74-
it('returns undefined when date is not null and should_format_null is false', () => {
74+
it('returns formatted date when date is not null and should_format_null is false', () => {
7575
const date = moment('2023-09-20').utc();
76-
expect(DateTime.formatDate(date, date_format, false)).toBeUndefined();
76+
expect(DateTime.formatDate(date, date_format, false)).toEqual(moment(date).format(date_format));
7777
});
7878
});
7979

packages/shared/src/utils/date/date-time.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const toGMTFormat = (time?: moment.MomentInput) =>
7474
.format('YYYY-MM-DD HH:mm:ss [GMT]');
7575

7676
export const formatDate = (date?: moment.MomentInput, date_format = 'YYYY-MM-DD', should_format_null = true) =>
77-
should_format_null && date !== null ? toMoment(date).format(date_format) : undefined;
77+
!should_format_null && date === null ? undefined : toMoment(date).format(date_format);
7878

7979
export const formatTime = (epoch: number | string, time_format = 'HH:mm:ss [GMT]') =>
8080
toMoment(epoch).format(time_format);

0 commit comments

Comments
 (0)