Skip to content

Commit

Permalink
fix(pci-savings-plan): add utc date on creation (#14447)
Browse files Browse the repository at this point in the history
ref: TAPC-1726

Signed-off-by: Lionel Bueno <[email protected]>
  • Loading branch information
lionel95200x authored Jan 3, 2025
1 parent 6997291 commit 5148b67
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/manager/apps/pci-savings-plan/src/pages/listing/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Outlet, useHref, useNavigate, useParams } from 'react-router-dom';
import { MutationStatus, useMutationState } from '@tanstack/react-query';
Expand All @@ -17,7 +17,7 @@ import {
OsdsMessage,
OsdsText,
} from '@ovhcloud/ods-components/react';

import { ShellContext } from '@ovh-ux/manager-react-shell-client';
import { Title } from '@ovh-ux/manager-react-components';

import TableContainer from '@/components/Table/TableContainer';
Expand All @@ -27,6 +27,7 @@ import {
useServiceId,
} from '@/hooks/useSavingsPlan';
import { SavingsPlanService } from '@/types';
import { toLocalDateUTC } from '@/utils/formatter/date';

export const formatDateString = (dateString: string, locale?: string) => {
const date = new Date(dateString);
Expand Down Expand Up @@ -88,6 +89,8 @@ const ListingTablePage: React.FC<ListingProps> = ({
refetchSavingsPlans,
}) => {
const { t } = useTranslation('listing');
const { environment } = useContext(ShellContext);
const locale = environment.getUserLocale();

const hrefDashboard = useHref('');
const serviceId = useServiceId();
Expand Down Expand Up @@ -160,11 +163,15 @@ const ListingTablePage: React.FC<ListingProps> = ({
{mutationSpCreate.length > 0 && !lastMutationSpCreate.error?.code && (
<Banner
message={t('banner_create_sp', {
startDate: lastMutationSpCreate.data.startDate,
startDate: toLocalDateUTC(
lastMutationSpCreate.data.startDate,
locale,
),
})}
key={lastMutationSpCreate.submittedAt}
/>
)}

{mutationSPEditName.length > 0 && (
<Banner
message={t('banner_edit_name')}
Expand Down
11 changes: 11 additions & 0 deletions packages/manager/apps/pci-savings-plan/src/utils/formatter/date.ts
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
export const formatDate = (date: Date) => date.toISOString().split('T')[0];

export const toLocalDateUTC = (date: string, locale: string) =>
new Date(date).toLocaleString(locale.replace('_', '-'), {
timeZone: 'UTC',
day: 'numeric',
month: 'short',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
timeZoneName: 'short',
});

0 comments on commit 5148b67

Please sign in to comment.