Skip to content

Commit

Permalink
imroved parseDate util
Browse files Browse the repository at this point in the history
  • Loading branch information
e11sy committed Jul 27, 2024
1 parent 059103e commit 63305c5
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions src/infrastructure/utils/parseDate.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
export function parseDate(date: Date): string {
// Массив с названиями месяцев
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

// Получаем название месяца
const month = months[date.getUTCMonth()];

// Получаем день
const day = date.getUTCDate();

// Получаем часы и минуты, добавляем ведущий ноль при необходимости
const hours = date.getUTCHours().toString()
.padStart(2, '0');
const minutes = date.getUTCMinutes().toString()
.padStart(2, '0');

// Формируем итоговую строку
return `${month} ${day}, ${hours}:${minutes}`;
return new Intl.DateTimeFormat('en-GB', {
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
}).format(date);
}

0 comments on commit 63305c5

Please sign in to comment.