Add status
This commit is contained in:
@@ -2,6 +2,12 @@ package storage
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
StatusOld = -1
|
||||
StatusOngoing = 0
|
||||
StatusForthcoming = 1
|
||||
)
|
||||
|
||||
type Booking struct {
|
||||
ID string `json:"id" bson:"_id"`
|
||||
Vehicleid string `json:"vehicleid"`
|
||||
@@ -15,3 +21,15 @@ type Booking struct {
|
||||
Deleted bool
|
||||
Vehicle Vehicle
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user