generated from VLADIMIR/template
update
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"pinned_message/internal/models"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ScheduleStorage struct {
|
||||
@@ -42,5 +43,19 @@ func (s *ScheduleStorage) GetSchedule() ([]*models.Day, error) {
|
||||
if err := json.Unmarshal(data, &days); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return days, nil
|
||||
filterDays := make([]*models.Day, 0, len(days))
|
||||
for _, day := range days {
|
||||
if isBeforeToday(day.Date) {
|
||||
continue
|
||||
}
|
||||
filterDays = append(filterDays, day)
|
||||
}
|
||||
return filterDays, nil
|
||||
}
|
||||
|
||||
func isBeforeToday(targetDate time.Time) bool {
|
||||
now := time.Now()
|
||||
todayMidnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||
targetMidnight := time.Date(targetDate.Year(), targetDate.Month(), targetDate.Day(), 0, 0, 0, 0, targetDate.Location())
|
||||
return targetMidnight.Before(todayMidnight)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user