diff --git a/src/app/lib/convertBytes.ts b/src/app/lib/convertBytes.ts new file mode 100644 index 0000000..b1886fe --- /dev/null +++ b/src/app/lib/convertBytes.ts @@ -0,0 +1,19 @@ +export function convertBytes(bytes: number) { + if (!bytes) { + return 0; + } + + const units = ['B', 'KB', 'MB', 'GB', 'TB']; + + if (bytes === 0) return '0 B'; + + let i = 0; + let value = bytes; + + while (value >= 1024 && i < units.length - 1) { + value /= 1024; + i++; + } + + return `${value.toFixed(1)} ${units[i]}`; +} diff --git a/src/app/lib/formatDate.ts b/src/app/lib/formatDate.ts new file mode 100644 index 0000000..0fa749c --- /dev/null +++ b/src/app/lib/formatDate.ts @@ -0,0 +1,25 @@ +// Форматирование даты из timestamp +export const formatDate = (timestamp: number | string) => { + if (!timestamp) { + return '---' + } + + const date = new Date(timestamp); + const day = date.getDate().toString().padStart(2, '0'); + const month = (date.getMonth() + 1).toString().padStart(2, '0'); + const year = date.getFullYear(); + + return `${day}.${month}.${year}`; +}; + +export const formatDateTime = (timestamp: number | string) => { + if (!timestamp) { + return '---' + } + + const date = new Date(timestamp); + const hours = date.getHours().toString().padStart(2, '0'); + const minutes = date.getMinutes().toString().padStart(2, '0'); + + return `${hours}:${minutes}`; +}; \ No newline at end of file diff --git a/src/app/ui/dashboard/general-info.tsx/general-info-users.tsx b/src/app/ui/dashboard/general-info.tsx/general-info-users.tsx index 2194c61..c3d58ea 100644 --- a/src/app/ui/dashboard/general-info.tsx/general-info-users.tsx +++ b/src/app/ui/dashboard/general-info.tsx/general-info-users.tsx @@ -16,6 +16,21 @@ export default function GeneralInfoUsers() { +