generated from VLADIMIR/template
update times
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"pinned_message/internal/models"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -50,6 +51,9 @@ func (s *ScheduleStorage) GetSchedule() (*models.Schedule, error) {
|
||||
continue
|
||||
}
|
||||
for i := range day.Performances {
|
||||
if day.Performances[i].TimeCollection == "" || day.Performances[i].TimeCollection == "-" {
|
||||
day.Performances[i].TimeCollection = GetStartTime(day.Performances[i].TimeStart)
|
||||
}
|
||||
filterNumbers := make([]*models.Number, 0, len(day.Performances[i].Numbers))
|
||||
for _, number := range day.Performances[i].Numbers {
|
||||
name := strings.TrimSpace(number.Name)
|
||||
@@ -72,3 +76,13 @@ func isBeforeToday(targetDate time.Time) bool {
|
||||
targetMidnight := time.Date(targetDate.Year(), targetDate.Month(), targetDate.Day(), 0, 0, 0, 0, targetDate.Location())
|
||||
return targetMidnight.Before(todayMidnight)
|
||||
}
|
||||
|
||||
// Компилируем регулярное выражение один раз (для производительности)
|
||||
// Ищем от 1 до 2 цифр, затем двоеточие, затем ровно 2 цифры
|
||||
var timeRegex = regexp.MustCompile(`\d{1,2}:\d{2}`)
|
||||
|
||||
// GetStartTime извлекает первое найденное время из строки
|
||||
func GetStartTime(timeRange string) string {
|
||||
// FindString возвращает самое первое совпадение в строке
|
||||
return timeRegex.FindString(timeRange)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user