fleets/storage/bookings.go

36 lines
782 B
Go
Raw Permalink Normal View History

2022-08-12 12:49:16 +00:00
package storage
import "time"
2022-11-01 23:25:21 +00:00
const (
StatusOld = -1
StatusOngoing = 0
StatusForthcoming = 1
)
2022-08-12 12:49:16 +00:00
type Booking struct {
ID string `json:"id" bson:"_id"`
Vehicleid string `json:"vehicleid"`
Driver string `json:"driver"`
Startdate time.Time `json:"startdate"`
Enddate time.Time `json:"enddate"`
Unavailablefrom time.Time `json:"unavailablefrom"`
Unavailableto time.Time `json:"unavailableto"`
Data map[string]any `json:"data"`
Deleted bool
Vehicle Vehicle
}
2022-11-01 23:25:21 +00:00
func (b Booking) Status() int {
now := time.Now()
if b.Enddate.Before(now) {
return StatusOld
} else if b.Startdate.After(now) {
return StatusForthcoming
} else {
return StatusOngoing
}
}