carpool-service/interoperability/ocss/schedules.go

63 lines
1.1 KiB
Go
Raw Normal View History

2023-03-27 18:54:56 +00:00
package ocss
import (
"bytes"
"encoding/json"
)
2023-03-27 18:54:56 +00:00
type Day int64
const (
Monday Day = iota
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
)
var daytoID = map[string]Day{
"MON": Monday,
"TUE": Tuesday,
"WED": Wednesday,
"THU": Thursday,
"FRI": Friday,
"SAT": Saturday,
"SUN": Sunday,
}
var daytoString = map[Day]string{
Monday: "MON",
Tuesday: "TUE",
Wednesday: "WED",
Thursday: "THU",
Friday: "FRI",
Saturday: "SAT",
Sunday: "SUN",
}
func (s Day) MarshalJSON() ([]byte, error) {
buffer := bytes.NewBufferString(`"`)
buffer.WriteString(daytoString[s])
buffer.WriteString(`"`)
return buffer.Bytes(), nil
}
func (bs *Day) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
if err != nil {
return err
}
// Note that if the string cannot be found then it will be set to the zero value, 'Created' in this case.
*bs = daytoID[j]
return nil
}
2023-03-27 18:54:56 +00:00
type Schedule struct {
PassengerPickupDay *Day `json:"passengerPickupDay,omitempty" bson:"passengerPickupDay,omitempty"`
2023-03-27 18:54:56 +00:00
JourneySchedules *[]JourneySchedule `json:"journeySchedules,omitempty" bson:"journeySchedules,omitempty"`
2023-03-27 18:54:56 +00:00
}