diff options
author | Anton Tananaev <anton@traccar.org> | 2024-05-09 07:24:14 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2024-05-09 07:24:14 -0700 |
commit | c4754d0befac1a0bfb85f56419dade8378b98b32 (patch) | |
tree | c71409e6e312848df9a537acf5870bddb2e81c9b /src/common | |
parent | f6d15a1a445a1abd18d89a803b8617957c6970b6 (diff) | |
download | trackermap-web-c4754d0befac1a0bfb85f56419dade8378b98b32.tar.gz trackermap-web-c4754d0befac1a0bfb85f56419dade8378b98b32.tar.bz2 trackermap-web-c4754d0befac1a0bfb85f56419dade8378b98b32.zip |
Automatic locale time formatting
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/components/PositionValue.jsx | 3 | ||||
-rw-r--r-- | src/common/util/formatter.js | 12 |
2 files changed, 8 insertions, 7 deletions
diff --git a/src/common/components/PositionValue.jsx b/src/common/components/PositionValue.jsx index b1f8f656..cedf47c9 100644 --- a/src/common/components/PositionValue.jsx +++ b/src/common/components/PositionValue.jsx @@ -42,14 +42,13 @@ const PositionValue = ({ position, property, attribute }) => { const speedUnit = useAttributePreference('speedUnit'); const volumeUnit = useAttributePreference('volumeUnit'); const coordinateFormat = usePreference('coordinateFormat'); - const hours12 = usePreference('twelveHourFormat'); const formatValue = () => { switch (key) { case 'fixTime': case 'deviceTime': case 'serverTime': - return formatTime(value, 'seconds', hours12); + return formatTime(value, 'seconds'); case 'latitude': return formatCoordinate('latitude', value, coordinateFormat); case 'longitude': diff --git a/src/common/util/formatter.js b/src/common/util/formatter.js index 0463df2b..b10d737a 100644 --- a/src/common/util/formatter.js +++ b/src/common/util/formatter.js @@ -1,6 +1,7 @@ import dayjs from 'dayjs'; import duration from 'dayjs/plugin/duration'; import relativeTime from 'dayjs/plugin/relativeTime'; +import localizedFormat from 'dayjs/plugin/localizedFormat'; import { altitudeFromMeters, @@ -16,6 +17,7 @@ import { prefixString } from './stringUtils'; dayjs.extend(duration); dayjs.extend(relativeTime); +dayjs.extend(localizedFormat); export const formatBoolean = (value, t) => (value ? t('sharedYes') : t('sharedNo')); @@ -29,18 +31,18 @@ export const formatVoltage = (value, t) => `${value.toFixed(2)} ${t('sharedVoltA export const formatConsumption = (value, t) => `${value.toFixed(2)} ${t('sharedLiterPerHourAbbreviation')}`; -export const formatTime = (value, format, hours12) => { +export const formatTime = (value, format) => { if (value) { const d = dayjs(value); switch (format) { case 'date': - return d.format('YYYY-MM-DD'); + return d.format('L'); case 'time': - return d.format(hours12 ? 'hh:mm:ss A' : 'HH:mm:ss'); + return d.format('LTS'); case 'minutes': - return d.format(hours12 ? 'YYYY-MM-DD hh:mm A' : 'YYYY-MM-DD HH:mm'); + return d.format('L LT'); default: - return d.format(hours12 ? 'YYYY-MM-DD hh:mm:ss A' : 'YYYY-MM-DD HH:mm:ss'); + return d.format('L LTS'); } } return ''; |