Skip to content

Commit

Permalink
fix(DocPage): change default region
Browse files Browse the repository at this point in the history
  • Loading branch information
Feverqwe committed Jan 16, 2024
1 parent 098dcfa commit 7192ec5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/components/UpdatedAtDate/UpdatedAtDate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {memo, useMemo} from 'react';

import block from 'bem-cn-lite';

import {configure, getConfig} from '../../config';
import {getConfig} from '../../config';
import {useTranslation} from '../../hooks';
import {format} from '../../utils/date';

Expand All @@ -20,9 +20,8 @@ const UpdatedAtDate: React.FC<UpdatedAtDateProps> = (props) => {
const {t} = useTranslation(translationName);

const updatedAtFormatted = useMemo(() => {
configure();
const config = getConfig();
return format(updatedAt, 'longDateTime', config.localeCode);
const {localeCode} = getConfig();
return format(updatedAt, 'longDateTime', localeCode);
}, [updatedAt]);

return (
Expand Down
10 changes: 8 additions & 2 deletions src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface DateTimeFormatter {
year: Intl.DateTimeFormat;
}

const defaultRegion = 'ru-RU';
const defaultRegion = 'en';

const dateTimeFormatters: Map<string, DateTimeFormatter> = new Map();

Expand Down Expand Up @@ -72,4 +72,10 @@ export const format = (
date: string | number,
formatCode: keyof DateTimeFormatter,
localeCode = defaultRegion,
) => getDateTimeFormatter(localeCode)[formatCode].format(new Date(date));
) => {
let result = getDateTimeFormatter(localeCode)[formatCode].format(new Date(date));
if (formatCode === 'longDate' && ['ru-RU', 'ru-KZ'].includes(localeCode)) {
result = result.replace(/\sг\.$/, '');
}
return result;
};

0 comments on commit 7192ec5

Please sign in to comment.