Skip to content

Commit

Permalink
fix wrong year date bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Lullabyq committed Dec 25, 2024
1 parent e6baeb4 commit 4cbe1eb
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/components/CustomLastUpdate/CustomLastUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,33 @@ import React from 'react';
import { translate } from '@docusaurus/Translate';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';

const NARROW_SPACE = '\u202F';
const NBSP = '\u00A0';

export const CustomLastUpdate = ({ lastUpdatedAt }: { lastUpdatedAt: number }): JSX.Element => {
const { i18n } = useDocusaurusContext();

const isRuLocale = i18n.currentLocale === 'ru';
const formattedUpdatedAt = lastUpdatedAt * 1000;

return (
<div className="rounded-sm bg-blue-50 px-1.5 py-0.5 text-blue-500 text-xs font-normal w-fit mb-3">
<span>
{translate({ id: 'lastUpdated.atDate', message: 'Обновлено: ' })}

<time dateTime={new Date(lastUpdatedAt * 1000).toISOString()}>
<time dateTime={new Date(formattedUpdatedAt).toISOString()}>
{new Intl.DateTimeFormat(i18n.currentLocale, {
day: 'numeric',
month: 'long',
year: isRuLocale ? undefined : 'numeric',
timeZone: 'UTC',
}).format(lastUpdatedAt)}
}).format(formattedUpdatedAt)}

{NARROW_SPACE}
{NBSP}

{isRuLocale &&
new Intl.DateTimeFormat('ru', {
year: 'numeric',
}).format(lastUpdatedAt)}
}).format(formattedUpdatedAt)}
</time>
</span>
</div>
Expand Down

0 comments on commit 4cbe1eb

Please sign in to comment.