Skip to content

Commit

Permalink
feat(utils): Add date formatting utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
vio committed Sep 28, 2019
1 parent 8724714 commit a3d582b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/utils/src/utils/date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* global navigator */
export const formatDate = (value) => {
const date = typeof value === 'string' ? new Date(value) : value;

return new Intl.DateTimeFormat(navigator.languages || [], {
day: '2-digit',
month: '2-digit',
year: 'numeric',
}).format(date);
};

export const formatTime = (value) => {
const date = typeof value === 'string' ? new Date(value) : value;

return new Intl.DateTimeFormat(navigator.languages || [], {
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
}).format(date);
};
1 change: 1 addition & 0 deletions packages/utils/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './create-report';
export * from './delta';
export * from './date';
export * from './extract-data';
export * from './format';

0 comments on commit a3d582b

Please sign in to comment.