Skip to content

Commit 6725adf

Browse files
FEATURE (time): Format last backup time in a short way
1 parent 8929ab3 commit 6725adf

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

frontend/src/features/databases/ui/DatabaseCardComponent.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import dayjs from 'dayjs';
33

44
import { type Database, DatabaseType } from '../../../entity/databases';
55
import { getStorageLogoFromType } from '../../../entity/storages';
6-
import { getUserTimeFormat } from '../../../shared/time';
6+
import { getUserShortTimeFormat } from '../../../shared/time/getUserTimeFormat';
77

88
interface Props {
99
database: Database;
@@ -51,9 +51,8 @@ export const DatabaseCardComponent = ({
5151
<div className="mt-3 mb-1 text-xs text-gray-500">
5252
<span className="font-bold">Last backup</span>
5353
<br />
54-
{dayjs(database.lastBackupTime).format(getUserTimeFormat().format)}
55-
<br />
56-
{dayjs(database.lastBackupTime).fromNow()}
54+
{dayjs(database.lastBackupTime).format(getUserShortTimeFormat().format)} (
55+
{dayjs(database.lastBackupTime).fromNow()})
5756
</div>
5857
)}
5958

frontend/src/shared/time/getUserTimeFormat.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,15 @@ export const getUserTimeFormat = () => {
99
format: is12Hour ? 'DD.MM.YYYY h:mm:ss A' : 'DD.MM.YYYY HH:mm:ss',
1010
};
1111
};
12+
13+
export const getUserShortTimeFormat = () => {
14+
const locale = navigator.language || 'en-US';
15+
const testDate = new Date(2023, 0, 1, 13, 0, 0); // 1 PM
16+
const timeString = testDate.toLocaleTimeString(locale, { hour: 'numeric' });
17+
const is12Hour = timeString.includes('PM') || timeString.includes('AM');
18+
19+
return {
20+
use12Hours: is12Hour,
21+
format: is12Hour ? 'DD.MM.YYYY h:mm A' : 'DD.MM.YYYY HH:mm',
22+
};
23+
};

0 commit comments

Comments
 (0)