Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

improvement: displaying one date if from === to

Blue Mouse20bf64515c75
diff --git a/src/redux/constants/index.js b/src/redux/constants/index.js
index a55794eaf..d27783bf4 100644
--- a/src/redux/constants/index.js
+++ b/src/redux/constants/index.js
@@ -1,3 +1,18 @@
+const getCustomLabel = (dates, t) => {
+ if (dates) {
+ const from = dates[0].toLocaleDateString()
+ const to = dates[1].toLocaleDateString()
+
+ if (from === to) {
+ return from
+ }
+
+ return `${from} - ${to}`
+ }
+
+ return t('project.custom')
+}
+
export const tbPeriodPairs = (t, tbs, dates) => [{
label: t('project.today'),
period: 'today',
@@ -39,7 +54,7 @@ export const tbPeriodPairs = (t, tbs, dates) => [{
tbs: ['month'],
access: 'paid',
}, {
- label: dates ? `${dates[0].toLocaleDateString()} - ${dates[1].toLocaleDateString()}` : t('project.custom'),
+ label: getCustomLabel(dates, t),
dropdownLabel: t('project.custom'),
isCustomDate: true,
period: 'custom',