63 lines
1.1 KiB
Go
63 lines
1.1 KiB
Go
package ocss
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
type Schedule struct {
|
|
PassengerPickupDay *Day `json:"passengerPickupDay,omitempty" bson:"passengerPickupDay,omitempty"`
|
|
|
|
JourneySchedules *[]JourneySchedule `json:"journeySchedules,omitempty" bson:"journeySchedules,omitempty"`
|
|
}
|