diff --git a/package.json b/package.json index 0d43e3d..13aa12f 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "clsx": "^2.1.1", "cookies-next": "^5.1.0", "date-fns": "^4.1.0", + "date-fns-tz": "^3.2.0", "embla-carousel-autoplay": "^8.6.0", "embla-carousel-react": "^8.6.0", "json-to-graphql-query": "^2.3.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index be73421..eb1dd52 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -71,6 +71,9 @@ importers: date-fns: specifier: ^4.1.0 version: 4.1.0 + date-fns-tz: + specifier: ^3.2.0 + version: 3.2.0(date-fns@4.1.0) embla-carousel-autoplay: specifier: ^8.6.0 version: 8.6.0(embla-carousel@8.6.0) @@ -1570,6 +1573,11 @@ packages: resolution: {integrity: sha512-BS8PfmtDGnrgYdOonGZQdLZslWIeCGFP9tpan0hi1Co2Zr2NKADsvGYA8XxuG/4UWgJ6Cjtv+YJnB6MM69QGlQ==} engines: {node: '>= 0.4'} + date-fns-tz@3.2.0: + resolution: {integrity: sha512-sg8HqoTEulcbbbVXeg84u5UnlsQa8GS5QXMqjjYIhS4abEVVKIUwe0/l/UhrZdKaL/W5eWZNlbTeEIiOXTcsBQ==} + peerDependencies: + date-fns: ^3.0.0 || ^4.0.0 + date-fns@4.1.0: resolution: {integrity: sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==} @@ -4228,6 +4236,10 @@ snapshots: es-errors: 1.3.0 is-data-view: 1.0.2 + date-fns-tz@3.2.0(date-fns@4.1.0): + dependencies: + date-fns: 4.1.0 + date-fns@4.1.0: {} debug@3.2.7: diff --git a/src/pages-templates/(dashboard)/corporate-dashboard/index.tsx b/src/pages-templates/(dashboard)/corporate-dashboard/index.tsx index 787b3ad..a5bc024 100644 --- a/src/pages-templates/(dashboard)/corporate-dashboard/index.tsx +++ b/src/pages-templates/(dashboard)/corporate-dashboard/index.tsx @@ -1,7 +1,6 @@ 'use client'; import { deleteCookie } from 'cookies-next'; -import { format } from 'date-fns'; import { Building2, LogOut, Wallet } from 'lucide-react'; import { useEffect, useState } from 'react'; @@ -12,6 +11,7 @@ import { import { CorporateTransactionRequest } from '@/entities/corporate/model/types/corporate-transactions.type'; import { useTextController } from '@/shared/language/hooks/use-text-controller'; +import { formatDate } from '@/shared/lib/format-date'; import { Button } from '@/shared/shadcn-ui/button'; import { Card, @@ -195,7 +195,7 @@ export function CorporateDashboard() { renderRow={(transaction, index) => ( - {format( + {formatDate( new Date(transaction.date_create), 'dd.MM.yyyy HH:mm', )} diff --git a/src/pages-templates/(dashboard)/customer-dashboard/index.tsx b/src/pages-templates/(dashboard)/customer-dashboard/index.tsx index 93496c8..d7f47ab 100644 --- a/src/pages-templates/(dashboard)/customer-dashboard/index.tsx +++ b/src/pages-templates/(dashboard)/customer-dashboard/index.tsx @@ -1,7 +1,6 @@ 'use client'; import { deleteCookie } from 'cookies-next'; -import { format } from 'date-fns'; import { ArrowUpRight, Clock, CreditCard, LogOut, User } from 'lucide-react'; import { useEffect, useState } from 'react'; @@ -13,6 +12,7 @@ import { BonusTransactionRequest } from '@/entities/bonus/model/types/bonus-tran import Loader from '@/shared/components/loader'; import { useTextController } from '@/shared/language/hooks/use-text-controller'; +import { formatDate } from '@/shared/lib/format-date'; import { Button } from '@/shared/shadcn-ui/button'; import { Card, @@ -190,10 +190,7 @@ export function CustomerDashboard() { renderRow={(transaction) => ( - {format( - new Date(transaction.date_create), - 'dd.MM.yyyy HH:mm', - )} + {formatDate(transaction.date_create, 'dd.MM.yyyy HH:mm')} {transaction.station} {transaction.product_name} diff --git a/src/shared/lib/format-date.ts b/src/shared/lib/format-date.ts new file mode 100644 index 0000000..69d9a79 --- /dev/null +++ b/src/shared/lib/format-date.ts @@ -0,0 +1,9 @@ +import { formatInTimeZone } from 'date-fns-tz'; + +export const formatDate = ( + date: Date | string, + formatStr: string = 'dd.MM.yyyy HH:mm', +) => { + const utcDate = new Date(date); + return formatInTimeZone(utcDate, 'UTC', formatStr); +};