update formats

This commit is contained in:
Владимир Фёдоров 2026-03-26 14:41:25 +07:00
parent 1884153d8c
commit baea739043
2 changed files with 39 additions and 3 deletions

View File

@ -2,7 +2,7 @@
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import { apiGetDays } from './client'; import { apiGetDays } from './client';
import type { Schedule } from './models'; import type { Schedule } from './models';
import { formatRussianDate, getRelativeDayName, timeAgo } from './date'; import { formatRussianDate, formatTime, getRelativeDayName, timeAgo, formatTimeRange } from './date';
import { capitalizeFirstLetter } from './text'; import { capitalizeFirstLetter } from './text';
const schedule = ref<Schedule>({ updateTime: "", days: [] }) const schedule = ref<Schedule>({ updateTime: "", days: [] })
@ -21,10 +21,10 @@ onMounted(async () => {
<div v-for="(performance, index) in day.performances" :key="performance.name" class="performance-block"> <div v-for="(performance, index) in day.performances" :key="performance.name" class="performance-block">
<hr v-if="index > 0" class="hr"> <hr v-if="index > 0" class="hr">
<div v-if="performance.timeCollection !== '' && performance.timeCollection !== '-'"> <div v-if="performance.timeCollection !== '' && performance.timeCollection !== '-'">
Сбор: {{ performance.timeCollection }} Сбор: {{ formatTime(performance.timeCollection) }}
</div> </div>
<div v-if="performance.timeStart !== '' && performance.timeStart !== '-'"> <div v-if="performance.timeStart !== '' && performance.timeStart !== '-'">
Время: {{ performance.timeStart }} Время: {{ formatTimeRange(performance.timeStart) }}
</div> </div>
<div> <div>
Место: {{ capitalizeFirstLetter(performance.place) }} Место: {{ capitalizeFirstLetter(performance.place) }}

View File

@ -149,3 +149,39 @@ export function timeAgo(goDateStr: string): string {
}); });
} }
export function formatTime(timeStr: string): string {
if (!timeStr) {
return "";
}
return timeStr
// 1. Убираем абсолютно все пробелы (включая табы и неразрывные пробелы)
.replace(/\s+/g, "")
// 2. Заменяем все точки на двоеточия
.replace(/\./g, ":");
}
export function formatTimeRange(text: string): string {
if (!text) {
return "";
}
return text
// 1. Меняем точку на двоеточие ТОЛЬКО в форматах времени (например, 16.00 -> 16:00)
// (^|[^\d]) - проверяем, что перед цифрой нет других цифр
// ([0-2]?\d) - часы (от 0 до 29)
// \. - сама точка
// ([0-5]\d) - минуты (от 00 до 59)
// (?!\d) - после минут не должно быть других цифр
.replace(/(^|[^\d])([0-2]?\d)\.([0-5]\d)(?!\d)/g, "$1$2:$3")
// 2. Находим любые дефисы или тире и делаем красивые пробелы вокруг них ("-" -> " - ")
.replace(/\s*([-–—])\s*/g, " - ")
// 3. На всякий случай сжимаем двойные пробелы в один (если они случайно появились)
.replace(/\s{2,}/g, " ")
// 4. Убираем пробелы в самом начале и в самом конце строки
.trim();
}