Test Func

mail@pastecode.io avatar
unknown
golang
2 years ago
2.1 kB
3
Indexable
Never
func (i *Flight) CountStatus() {
	if time.Since(i.DepartureDate) > time.Hour*24 {
		i.Status = FlightStatus_StatusH
		return
	}
	if i.Status == FlightStatus_StatusC ||
		i.Status == FlightStatus_StatusCO ||
		i.Status == FlightStatus_StatusD ||
		i.Status == FlightStatus_StatusH ||
		i.Status == FlightStatus_StatusNo ||
		i.Status == FlightStatus_StatusR ||
		i.Status == FlightStatus_StatusU {
		return
	} else {
		departureDate := i.DepartureDate
		if i.ActualDepartureDate != nil {
			departureDate = *i.ActualDepartureDate
		}
		if time.Since(departureDate) > time.Hour*24 {
			i.Status = FlightStatus_StatusH
		}
		arrivalDate := i.ArrivalDate
		if i.ActualArrivalDate != nil {
			arrivalDate = *i.ActualArrivalDate
		}
		if time.Since(arrivalDate) > 0 {
			after := time.Since(arrivalDate)
			if after > time.Hour*2 {
				i.Status = FlightStatus_StatusCO
			}
			i.Status = FlightStatus_StatusL
		} else {

			if time.Since(departureDate) > 0 {
				i.Status = FlightStatus_StatusA
				return
			}
			before := time.Since(departureDate)
			if before < 0 {
				before = -before
			}
			if before < time.Hour*24 {
				timeToReg := time.Hour * 3
				iternational := i.Departure.CountryCode != i.Arrival.CountryCode
				if iternational {
					if i.Airline.TimeToRegistrationAbroad != nil {
						timeToReg = time.Duration(int(*i.Airline.TimeToRegistrationAbroad)) * time.Minute
					} else {
						timeToReg = time.Hour * 4
					}
				} else if i.Airline.TimeToRegistration != nil {
					timeToReg = time.Duration(int(*i.Airline.TimeToRegistration)) * time.Minute
				}
				if before < timeToReg {
					if before < time.Minute*40 {
						if before < time.Minute*25 {
							i.Status = FlightStatus_StatusDP
							return
						} else {
							i.Status = FlightStatus_StatusBS
							return
						}
					} else {
						if i.Status == FlightStatus_StatusB {
							return
						}
						i.Status = FlightStatus_StatusCHS
						return
					}
				} else {
					i.Status = FlightStatus_StatusCH
					return
				}
			} else {
				i.Status = FlightStatus_StatusS
				return
			}
		}
	}
}