diff --git a/packages/utils/src/utils/date.js b/packages/utils/src/utils/date.js new file mode 100644 index 0000000000..ccd287a238 --- /dev/null +++ b/packages/utils/src/utils/date.js @@ -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); +}; diff --git a/packages/utils/src/utils/index.js b/packages/utils/src/utils/index.js index 38db24a16e..42f2ab986c 100644 --- a/packages/utils/src/utils/index.js +++ b/packages/utils/src/utils/index.js @@ -1,4 +1,5 @@ export * from './create-report'; export * from './delta'; +export * from './date'; export * from './extract-data'; export * from './format';