Skip to content

Commit

Permalink
comments are addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
atiqueahmedziad committed Aug 21, 2020
1 parent 48cb2e2 commit b613cef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
23 changes: 6 additions & 17 deletions src/lib/formatters.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
export function dateTimeFormat(timestamp, options) {
const dateTime = new Date(timestamp);
const timeFormatOptions = {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
};
const time = new Intl.DateTimeFormat(undefined, timeFormatOptions).format(
dateTime
);
const timeFormatOptions = { timeStyle: 'medium' };
const dateFormatOptions = { dateStyle: 'medium' };

if (options?.timeOnly) {
return time;
}
const chosenOption = options?.timeOnly
? timeFormatOptions
: { ...timeFormatOptions, ...dateFormatOptions };

const dateFormatOptions = { month: 'short', day: 'numeric', year: 'numeric' };
const date = new Intl.DateTimeFormat(undefined, dateFormatOptions).format(
dateTime
);

return `${date} ${time}`;
return new Intl.DateTimeFormat(undefined, chosenOption).format(dateTime);
}
5 changes: 2 additions & 3 deletions tests/ext-activitylog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,13 @@ test('timestamp is formatted and rendered correctly', () => {
const timeZone = { timeZone: 'UTC' };
// For log timestamp: 1597686226302
const expectedTime = '5:43:46 PM';
const expectedDateTime = `Aug 17, 2020 5:43:46 PM`;
const expectedDateTime = `Aug 17, 2020, 5:43:46 PM`;

const { activityLog } = new ActivityLog();
// To have consistant date time format, we choose "en-US" date time formatting and UTC timezone.
IntlDateTimeFormatFn.mockImplementation(function (zone, options) {
Object.assign(options, timeZone);
this.format = (date) =>
new originalIntlDateTimeFormat('en-US', options).format(date);
return new originalIntlDateTimeFormat('en-US', options);
});

activityLog.handleNewLogs(logs);
Expand Down

0 comments on commit b613cef

Please sign in to comment.