Skip to content

Commit 63305c5

Browse files
committed
imroved parseDate util
1 parent 059103e commit 63305c5

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

src/infrastructure/utils/parseDate.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
11
export function parseDate(date: Date): string {
2-
// Массив с названиями месяцев
3-
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
4-
5-
// Получаем название месяца
6-
const month = months[date.getUTCMonth()];
7-
8-
// Получаем день
9-
const day = date.getUTCDate();
10-
11-
// Получаем часы и минуты, добавляем ведущий ноль при необходимости
12-
const hours = date.getUTCHours().toString()
13-
.padStart(2, '0');
14-
const minutes = date.getUTCMinutes().toString()
15-
.padStart(2, '0');
16-
17-
// Формируем итоговую строку
18-
return `${month} ${day}, ${hours}:${minutes}`;
2+
return new Intl.DateTimeFormat('en-GB', {
3+
month: 'short',
4+
day: 'numeric',
5+
hour: 'numeric',
6+
minute: 'numeric',
7+
}).format(date);
198
}

0 commit comments

Comments
 (0)