📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
feature: time format 12h or 24h
kruzhambus1025c6c0cb9d
diff --git a/src/api/index.js b/src/api/index.jsindex 48f6e3f2d..0556fb49c 100644--- a/src/api/index.js+++ b/src/api/index.js@@ -522,3 +522,14 @@ export const deleteAlert = (id) =>? error.response.data: error.response.data.message})++export const setTimeFormat = (timeFormat) =>+ api+ .put('user/change-time-format', { timeFormat })+ .then((response) => response.data)+ .catch((error) => {+ debug('%s', error)+ throw _isEmpty(error.response.data?.message)+ ? error.response.data+ : error.response.data.message+ })diff --git a/src/pages/Project/View/ViewProject.helpers.jsx b/src/pages/Project/View/ViewProject.helpers.jsxindex d68a13e60..c3c94016c 100644--- a/src/pages/Project/View/ViewProject.helpers.jsx+++ b/src/pages/Project/View/ViewProject.helpers.jsx@@ -18,7 +18,7 @@ import _fill from 'lodash/fill'import _reduce from 'lodash/reduce'import JSZip from 'jszip'-import { tbsFormatMapper } from 'redux/constants'+import { TimeFormat, tbsFormatMapper, tbsFormatMapperXAxis } from 'redux/constants'import { getTimeFromSeconds, getStringFromTime, sumArrays } from 'utils/generic'import countries from 'utils/isoCountries'@@ -236,7 +236,7 @@ const getColumnsPerf = (chart, activeChartMetrics) => {const noRegionPeriods = ['custom', 'yesterday']// function to get the settings and data for the chart(main diagram)-const getSettings = (chart, timeBucket, activeChartMetrics, applyRegions) => {+const getSettings = (chart, timeBucket, activeChartMetrics, applyRegions, timeFormat) => {const xAxisSize = _size(chart.x)let regions@@ -317,7 +317,9 @@ const getSettings = (chart, timeBucket, activeChartMetrics, applyRegions) => {x: {tick: {fit: true,+ format: timeFormat === TimeFormat['24-hour'] ? (x) => d3.timeFormat(tbsFormatMapperXAxis[timeBucket])(x) : null,},+ localtime: timeFormat === TimeFormat['24-hour'],type: 'timeseries',},y2: {diff --git a/src/pages/Project/View/ViewProject.jsx b/src/pages/Project/View/ViewProject.jsxindex 94fce726f..c2e982030 100644--- a/src/pages/Project/View/ViewProject.jsx+++ b/src/pages/Project/View/ViewProject.jsx@@ -34,7 +34,7 @@ import Title from 'components/Title'import EventsRunningOutBanner from 'components/EventsRunningOutBanner'import {tbPeriodPairs, getProjectCacheKey, LIVE_VISITORS_UPDATE_INTERVAL, DEFAULT_TIMEZONE, CDN_URL, isDevelopment,- timeBucketToDays, getProjectCacheCustomKey, roleViewer, MAX_MONTHS_IN_PAST, MAX_MONTHS_IN_PAST_FREE, PROJECT_TABS,+ timeBucketToDays, getProjectCacheCustomKey, roleViewer, MAX_MONTHS_IN_PAST, MAX_MONTHS_IN_PAST_FREE, PROJECT_TABS, TimeFormat,} from 'redux/constants'import Button from 'ui/Button'import Loader from 'ui/Loader'@@ -131,6 +131,7 @@ const ViewProject = ({const [chartDataPerf, setChartDataPerf] = useState({})const [isPanelsDataEmptyPerf, setIsPanelsDataEmptyPerf] = useState(false)const [panelsDataPerf, setPanelsDataPerf] = useState({})+ const timeFormat = useMemo(() => user.timeFormat || TimeFormat['12-hour'], [user])const tabs = useMemo(() => {return [@@ -340,7 +341,7 @@ const ViewProject = ({setIsPanelsDataEmpty(true)} else {const applyRegions = !_includes(noRegionPeriods, activePeriod.period)- const bbSettings = getSettings(chart, timeBucket, activeChartMetrics, applyRegions)+ const bbSettings = getSettings(chart, timeBucket, activeChartMetrics, applyRegions, timeFormat)setChartData(chart)setPanelsData({@@ -639,7 +640,7 @@ const ViewProject = ({if (activeChartMetrics.bounce || activeChartMetrics.sessionDuration) {const applyRegions = !_includes(noRegionPeriods, activePeriod.period)- const bbSettings = getSettings(chartData, timeBucket, activeChartMetrics, applyRegions)+ const bbSettings = getSettings(chartData, timeBucket, activeChartMetrics, applyRegions, timeFormat)if (!_isEmpty(mainChart)) {mainChart.destroy()@@ -654,7 +655,7 @@ const ViewProject = ({if (!activeChartMetrics.bounce || !activeChartMetrics.sessionDuration) {const applyRegions = !_includes(noRegionPeriods, activePeriod.period)- const bbSettings = getSettings(chartData, timeBucket, activeChartMetrics, applyRegions)+ const bbSettings = getSettings(chartData, timeBucket, activeChartMetrics, applyRegions, timeFormat)if (!_isEmpty(mainChart)) {mainChart.destroy()diff --git a/src/pages/UserSettings/UserSettings.jsx b/src/pages/UserSettings/UserSettings.jsxindex ec41bde27..288f38b36 100644--- a/src/pages/UserSettings/UserSettings.jsx+++ b/src/pages/UserSettings/UserSettings.jsx@@ -19,7 +19,7 @@ import utc from 'dayjs/plugin/utc'import {reportFrequencies, DEFAULT_TIMEZONE, WEEKLY_REPORT_FREQUENCY, CONFIRMATION_TIMEOUT,- GDPR_REQUEST, GDPR_EXPORT_TIMEFRAME, THEME_TYPE,+ GDPR_REQUEST, GDPR_EXPORT_TIMEFRAME, THEME_TYPE, TimeFormat,} from 'redux/constants'import Title from 'components/Title'import { withAuthentication, auth } from 'hoc/protected'@@ -36,7 +36,7 @@ import routes from 'routes'import { trackCustom } from 'utils/analytics'import { getCookie, setCookie } from 'utils/cookie'import {- confirmEmail, exportUserData, generateApiKey, deleteApiKey, setTheme,+ confirmEmail, exportUserData, generateApiKey, deleteApiKey, setTheme, setTimeFormat,} from 'api'import ProjectList from './components/ProjectList'import TwoFA from './components/TwoFA'@@ -72,6 +72,7 @@ const UserSettings = ({const [error, setError] = useState(null)const [copied, setCopied] = useState(false)const translatedFrequencies = _map(reportFrequencies, (key) => t(`profileSettings.${key}`)) // useMemo(_map(reportFrequencies, (key) => t(`profileSettings.${key}`)), [t])+ const [timeFormat, setTimeFormatState] = useState(user.timeFormat || TimeFormat['12-hour'])const copyTimerRef = useRef(null)@@ -279,6 +280,17 @@ const UserSettings = ({}}+ const setAsyncTimeFormat = async () => {+ await setTimeFormat(timeFormat)+ .then((response) => {+ const { data } = response+ updateUserData(data)+ })+ .catch((e) => {+ updateProfileFailed(e)+ })+ }+return (<Title title={t('titles.profileSettings')}><div className='min-h-min-footer bg-gray-50 dark:bg-gray-800 flex flex-col py-6 px-4 sm:px-6 lg:px-8'>@@ -358,6 +370,23 @@ const UserSettings = ({<Button className='mt-4' onClick={handleTimezoneSave} primary large>{t('common.save')}</Button>+ <h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>+ {t('profileSettings.timeFormat')}+ </h3>+ <div className='grid grid-cols-1 gap-y-6 gap-x-4 lg:grid-cols-2 mt-4'>+ <div>+ <Select+ title={timeFormat}+ label={t('profileSettings.selectTimeFormat')}+ className='w-full'+ items={[TimeFormat['12-hour'], TimeFormat['24-hour']]}+ onSelect={(f) => setTimeFormatState(f)}+ />+ </div>+ </div>+ <Button className='mt-4' onClick={setAsyncTimeFormat} primary large>+ {t('common.save')}+ </Button><hr className='mt-5 border-gray-200 dark:border-gray-600' /><h3 className='mt-2 text-lg font-bold text-gray-900 dark:text-gray-50'>{t('profileSettings.email')}diff --git a/src/redux/constants/index.js b/src/redux/constants/index.jsindex 2985e30d3..2d014bf6a 100644--- a/src/redux/constants/index.js+++ b/src/redux/constants/index.js@@ -81,6 +81,18 @@ export const tbsFormatMapper = {month: '%d %B %Y',}+export const tbsFormatMapperXAxis = {+ hour: '%H:%M',+ day: '%d %B',+ week: '%d %B',+ month: '%d %B %Y',+}++export const TimeFormat = {+ '12-hour': '12-hour',+ '24-hour': '24-hour',+}+export const FREE_TIER_KEY = 'free'// a dedicated variable is needed for paid tier checking