fix: format-date without localizing

This commit is contained in:
BunyodL 2025-05-21 22:06:33 +05:00
parent 3321395b7f
commit 88f9fdd25c
5 changed files with 26 additions and 7 deletions

View File

@ -31,6 +31,7 @@
"clsx": "^2.1.1", "clsx": "^2.1.1",
"cookies-next": "^5.1.0", "cookies-next": "^5.1.0",
"date-fns": "^4.1.0", "date-fns": "^4.1.0",
"date-fns-tz": "^3.2.0",
"embla-carousel-autoplay": "^8.6.0", "embla-carousel-autoplay": "^8.6.0",
"embla-carousel-react": "^8.6.0", "embla-carousel-react": "^8.6.0",
"json-to-graphql-query": "^2.3.0", "json-to-graphql-query": "^2.3.0",

12
pnpm-lock.yaml generated
View File

@ -71,6 +71,9 @@ importers:
date-fns: date-fns:
specifier: ^4.1.0 specifier: ^4.1.0
version: 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: embla-carousel-autoplay:
specifier: ^8.6.0 specifier: ^8.6.0
version: 8.6.0(embla-carousel@8.6.0) version: 8.6.0(embla-carousel@8.6.0)
@ -1570,6 +1573,11 @@ packages:
resolution: {integrity: sha512-BS8PfmtDGnrgYdOonGZQdLZslWIeCGFP9tpan0hi1Co2Zr2NKADsvGYA8XxuG/4UWgJ6Cjtv+YJnB6MM69QGlQ==} resolution: {integrity: sha512-BS8PfmtDGnrgYdOonGZQdLZslWIeCGFP9tpan0hi1Co2Zr2NKADsvGYA8XxuG/4UWgJ6Cjtv+YJnB6MM69QGlQ==}
engines: {node: '>= 0.4'} 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: date-fns@4.1.0:
resolution: {integrity: sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==} resolution: {integrity: sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==}
@ -4228,6 +4236,10 @@ snapshots:
es-errors: 1.3.0 es-errors: 1.3.0
is-data-view: 1.0.2 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: {} date-fns@4.1.0: {}
debug@3.2.7: debug@3.2.7:

View File

@ -1,7 +1,6 @@
'use client'; 'use client';
import { deleteCookie } from 'cookies-next'; import { deleteCookie } from 'cookies-next';
import { format } from 'date-fns';
import { Building2, LogOut, Wallet } from 'lucide-react'; import { Building2, LogOut, Wallet } from 'lucide-react';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
@ -12,6 +11,7 @@ import {
import { CorporateTransactionRequest } from '@/entities/corporate/model/types/corporate-transactions.type'; import { CorporateTransactionRequest } from '@/entities/corporate/model/types/corporate-transactions.type';
import { useTextController } from '@/shared/language/hooks/use-text-controller'; import { useTextController } from '@/shared/language/hooks/use-text-controller';
import { formatDate } from '@/shared/lib/format-date';
import { Button } from '@/shared/shadcn-ui/button'; import { Button } from '@/shared/shadcn-ui/button';
import { import {
Card, Card,
@ -195,7 +195,7 @@ export function CorporateDashboard() {
renderRow={(transaction, index) => ( renderRow={(transaction, index) => (
<TableRow key={index}> <TableRow key={index}>
<TableCell> <TableCell>
{format( {formatDate(
new Date(transaction.date_create), new Date(transaction.date_create),
'dd.MM.yyyy HH:mm', 'dd.MM.yyyy HH:mm',
)} )}

View File

@ -1,7 +1,6 @@
'use client'; 'use client';
import { deleteCookie } from 'cookies-next'; import { deleteCookie } from 'cookies-next';
import { format } from 'date-fns';
import { ArrowUpRight, Clock, CreditCard, LogOut, User } from 'lucide-react'; import { ArrowUpRight, Clock, CreditCard, LogOut, User } from 'lucide-react';
import { useEffect, useState } from '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 Loader from '@/shared/components/loader';
import { useTextController } from '@/shared/language/hooks/use-text-controller'; import { useTextController } from '@/shared/language/hooks/use-text-controller';
import { formatDate } from '@/shared/lib/format-date';
import { Button } from '@/shared/shadcn-ui/button'; import { Button } from '@/shared/shadcn-ui/button';
import { import {
Card, Card,
@ -190,10 +190,7 @@ export function CustomerDashboard() {
renderRow={(transaction) => ( renderRow={(transaction) => (
<TableRow key={transaction.id}> <TableRow key={transaction.id}>
<TableCell> <TableCell>
{format( {formatDate(transaction.date_create, 'dd.MM.yyyy HH:mm')}
new Date(transaction.date_create),
'dd.MM.yyyy HH:mm',
)}
</TableCell> </TableCell>
<TableCell>{transaction.station}</TableCell> <TableCell>{transaction.station}</TableCell>
<TableCell>{transaction.product_name}</TableCell> <TableCell>{transaction.product_name}</TableCell>

View File

@ -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);
};