Skip to content

Commit

Permalink
Added format Date object using custom format with localization
Browse files Browse the repository at this point in the history
  • Loading branch information
GGO-web committed Sep 24, 2023
1 parent 48386f5 commit 83c8210
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 52 deletions.
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 12 additions & 16 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { ICarouselItem } from './types/constants';
import { v4 } from 'uuid';
import { getImageUrl } from '@helpers/getImageUrl';
import dayjs from 'dayjs';

const currentDate = dayjs();

export const carouselItems: ICarouselItem[] = [
{
Expand Down Expand Up @@ -380,35 +377,34 @@ export const DESCRIPTION_ANIME = {
'Між живим і мертвим світом дуже тонка грань. Нерідко породження пекла порушують цю межу. Вони проникають в тіла в чоловіків, жінок і навіть дітей, починаючи творити щось жахливе. Окультист і мисливець за усілякою нечистю Джон Костянтин не зовсім звичайна людина. На ньому лежить жахлива печать самогубці. Джон побував на тому світі і зміг повернутися в нормальне життя. Тепер за сюжетом мультсеріалу "Костянтин" він володіє древніми знаннями, які допомагають йому відправляти демонів назад у пекло. Людям він допомагає позбутися від темної сутності, проводячи необхідні обряди екзорцизму.\n Звичайно у Джона є маса недоліків. Він багато курить, що негативно позначається на його здоров\'ї. Однак безвідмовний дробовик завжди з ним. Темні сили природно бажають з ним розправитися. Вони придумують різні витончені способи знищити Костянтина. У цій боротьбі мисливцеві допомагає гострий розум і чудове знання свого супротивника. Часто доводиться діяти одному, оскільки навіть кохана дівчина не зовсім розуміє Джона.'
};

export const LIST_RELEASE_SCHEDULE = [
export interface SeriesReleaseScheduleItem {
id: string;
season: number;
series: number;
episode: number;
date: Date;
}

export const LIST_RELEASE_SCHEDULE: SeriesReleaseScheduleItem[] = [
{
id: v4(),
season: 1,
series: 5,
episode: 5,
day: currentDate.date(),
month: currentDate.format('MMMM'),
year: currentDate.year(),
dayWeek: currentDate.format('dddd')
date: new Date()
},
{
id: v4(),
season: 1,
series: 4,
episode: 4,
day: currentDate.date(),
month: currentDate.format('MMMM'),
year: currentDate.year(),
dayWeek: currentDate.format('dddd')
date: new Date()
},
{
id: v4(),
season: 1,
series: 3,
episode: 3,
day: currentDate.date(),
month: currentDate.format('MMMM'),
year: currentDate.year(),
dayWeek: currentDate.format('dddd')
date: new Date()
}
];
10 changes: 10 additions & 0 deletions src/helpers/formatDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import dayjs from 'dayjs';
import uaLocale from 'dayjs/locale/uk';
import advancedFormat from 'dayjs/plugin/advancedFormat';

dayjs.extend(advancedFormat);
dayjs.locale(uaLocale);

export const formatDate = (date: Date, format = 'D MMM YYYY, dd') => {
return dayjs(date).format(format);
};
4 changes: 2 additions & 2 deletions src/hooks/useDynamicSvgImport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useEffect, useRef, useState} from 'react';
import { useEffect, useRef, useState } from 'react';

export function useDynamicSvgImport(iconName: string) {
const importedIconRef = useRef<React.FC<React.SVGProps<SVGElement>>>();
Expand All @@ -24,5 +24,5 @@ export function useDynamicSvgImport(iconName: string) {
importSvgIcon();
}, [iconName]);

return {error, loading, SvgIcon: importedIconRef.current};
return { error, loading, SvgIcon: importedIconRef.current };
}
Original file line number Diff line number Diff line change
@@ -1,45 +1,27 @@
import { Heading } from '@components/Heading/Heading';

import React from 'react';
import { LENGTH_CHARS_3 } from '../../../../constants';
import { SeriesReleaseScheduleItem } from '../../../../constants';
import { formatDate } from '@helpers/formatDate';

interface SeriesReleaseScheduleProps {
listSeries: {
id: string;
season: number;
series: number;
episode: number;
day: number;
month: string;
year: number;
dayWeek: string;
}[];
}

export const SeriesReleaseSchedule: React.FC<SeriesReleaseScheduleProps> = ({
listSeries
}) => {
export const SeriesReleaseSchedule: React.FC<{
listSeries: SeriesReleaseScheduleItem[];
}> = ({ listSeries }) => {
return (
<div className="series-release-schedule">
<Heading className="text-xl mb-5">Графік виходу серій:</Heading>
<div className="series-release-schedule__list">
{listSeries.map(
({ id, season, series, day, episode, year, month, dayWeek }) => {
const shortenedMonth = month.slice(0, LENGTH_CHARS_3);

return (
<div key={id} className="series-release-schedule__item">
<p>
{season} сезон {series} серія
</p>
<p>Episode {episode}</p>
<p>
{day} {shortenedMonth} {year} {dayWeek}
</p>
</div>
);
}
)}
{listSeries.map(({ id, season, series, episode, date }) => {
return (
<div key={id} className="series-release-schedule__item">
<p>
{season} сезон {series} серія
</p>
<p>Episode {episode}</p>
<p>{formatDate(date)}</p>
</div>
);
})}
</div>
</div>
);
Expand Down

0 comments on commit 83c8210

Please sign in to comment.