Files
uta-trax-api/pkg/gtfs/gtfs.go
T
2026-10-11 13:05:44 -06:00

39 lines
719 B
Go

package gtfs
import (
"database/sql"
"time"
)
func GetActiveServiceIDs(t *time.Time, db *sql.DB) ([]string, error) {
weekday := t.Weekday()
rows, err := db.Query(`select service_id from calendar
WHERE (
case $1
when 0 then sunday
when 1 then monday
when 2 then tuesday
when 3 then wednesday
when 4 then thursday
when 5 then friday
when 6 then saturday
end
) AND $2 >= start_date AND $2 <= end_date
union
select service_id from calendar_dates where date = $2;`, weekday, t.Format("20060102"))
if err != nil {
return nil, err
}
result := []string{}
for rows.Next() {
var serviceId string
rows.Scan(&serviceId)
result = append(result, serviceId)
}
return result, nil
}