From a3d582bdd6b89721d8633d4d3d4b30e38fb9246d Mon Sep 17 00:00:00 2001 From: Vio Date: Sat, 28 Sep 2019 10:23:06 +0200 Subject: [PATCH] feat(utils): Add date formatting utilities --- packages/utils/src/utils/date.js | 20 ++++++++++++++++++++ packages/utils/src/utils/index.js | 1 + 2 files changed, 21 insertions(+) create mode 100644 packages/utils/src/utils/date.js 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';