package httpapi import ( "fmt" "time" "calllinesystem/server/internal/model" "gorm.io/gorm" ) func (s *Server) businessDateFor(project model.Project) (time.Time, error) { location, err := time.LoadLocation(project.Timezone) if err != nil { return time.Time{}, fmt.Errorf("invalid project timezone: %w", err) } localNow := s.now().In(location) return time.Date(localNow.Year(), localNow.Month(), localNow.Day(), 0, 0, 0, 0, location), nil } func (s *Server) currentQueueSession(db *gorm.DB, project model.Project) (model.QueueSession, error) { businessDate, err := s.businessDateFor(project) if err != nil { return model.QueueSession{}, err } var session model.QueueSession err = db.Where( "project_id = ? AND business_date = ? AND status IN ?", project.ID, businessDate, []string{"RUNNING", "PAUSED"}, ).First(&session).Error return session, err } func (s *Server) queueSessionIsCurrent(project model.Project, session model.QueueSession) (bool, error) { businessDate, err := s.businessDateFor(project) if err != nil { return false, err } return session.BusinessDate.Format("2006-01-02") == businessDate.Format("2006-01-02"), nil }