-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix flight schedules conversion handling of legs on the next day
previously, flights conversion saved the result file using the same date used to query from the LH API. When there is a flight with multiple legs, where one log falls into the next day (e.g. 4Y136), the flight was saved to the wrong flights file. This fix handles this by always taking the UTC departure date after conversion of legs to flights, then upserting the existing file if it exists
- Loading branch information
Showing
24 changed files
with
444 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package common | ||
|
||
import ( | ||
"maps" | ||
) | ||
|
||
type FlightScheduleData struct { | ||
DepartureTime OffsetTime `json:"departureTime"` | ||
DepartureAirport string `json:"departureAirport"` | ||
ArrivalTime OffsetTime `json:"arrivalTime"` | ||
ArrivalAirport string `json:"arrivalAirport"` | ||
ServiceType string `json:"serviceType"` | ||
AircraftOwner AirlineIdentifier `json:"aircraftOwner"` | ||
AircraftType string `json:"aircraftType"` | ||
AircraftConfigurationVersion string `json:"aircraftConfigurationVersion"` | ||
Registration string `json:"registration"` | ||
DataElements map[int]string `json:"dataElements"` | ||
CodeShares []FlightNumber `json:"codeShares"` | ||
} | ||
|
||
func (fsd FlightScheduleData) Equal(other FlightScheduleData) bool { | ||
return fsd.DepartureTime == other.DepartureTime && | ||
fsd.DepartureAirport == other.DepartureAirport && | ||
fsd.ArrivalTime == other.ArrivalTime && | ||
fsd.ArrivalAirport == other.ArrivalAirport && | ||
fsd.ServiceType == other.ServiceType && | ||
fsd.AircraftOwner == other.AircraftOwner && | ||
fsd.AircraftType == other.AircraftType && | ||
fsd.AircraftConfigurationVersion == other.AircraftConfigurationVersion && | ||
fsd.Registration == other.Registration && | ||
maps.Equal(fsd.DataElements, other.DataElements) && | ||
SliceEqualContent(fsd.CodeShares, other.CodeShares) | ||
} | ||
|
||
type FlightScheduleVariant struct { | ||
Ranges []LocalDateRange `json:"ranges"` | ||
Data FlightScheduleData `json:"data"` | ||
} | ||
|
||
func (fsv *FlightScheduleVariant) Expand(d LocalDate) { | ||
|
||
} | ||
|
||
type FlightSchedule struct { | ||
Airline AirlineIdentifier `json:"airline"` | ||
FlightNumber int `json:"flightNumber"` | ||
Suffix string `json:"suffix"` | ||
Variants []*FlightScheduleVariant `json:"variants"` | ||
} | ||
|
||
func (fs *FlightSchedule) DataVariant(fsd FlightScheduleData) *FlightScheduleVariant { | ||
for _, variant := range fs.Variants { | ||
if variant.Data.Equal(fsd) { | ||
return variant | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package common | ||
|
||
import ( | ||
"encoding/json" | ||
"time" | ||
) | ||
|
||
const offsetTimeFormat = "15:04:05Z07:00" | ||
|
||
type OffsetTime struct { | ||
Hour int | ||
Min int | ||
Sec int | ||
Loc *time.Location | ||
} | ||
|
||
func NewOffsetTime(t time.Time) OffsetTime { | ||
hour, minute, sec := t.Clock() | ||
return OffsetTime{ | ||
Hour: hour, | ||
Min: minute, | ||
Sec: sec, | ||
Loc: t.Location(), | ||
} | ||
} | ||
|
||
func ParseOffsetTime(v string) (OffsetTime, error) { | ||
t, err := time.Parse(offsetTimeFormat, v) | ||
if err != nil { | ||
return OffsetTime{}, err | ||
} | ||
|
||
return OffsetTime{ | ||
Hour: t.Hour(), | ||
Min: t.Minute(), | ||
Sec: t.Second(), | ||
Loc: t.Location(), | ||
}, nil | ||
} | ||
|
||
func MustParseOffsetTime(v string) OffsetTime { | ||
t, err := ParseOffsetTime(v) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return t | ||
} | ||
|
||
func (t OffsetTime) Time(d LocalDate) time.Time { | ||
return time.Date(d.Year, d.Month, d.Day, t.Hour, t.Min, t.Sec, 0, t.Loc) | ||
} | ||
|
||
func (t OffsetTime) String() string { | ||
return t.Time(LocalDate{}).Format(offsetTimeFormat) | ||
} | ||
|
||
func (t *OffsetTime) UnmarshalJSON(data []byte) error { | ||
var v string | ||
if err := json.Unmarshal(data, &v); err != nil { | ||
return err | ||
} | ||
|
||
r, err := time.Parse(offsetTimeFormat, v) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
*t = NewOffsetTime(r) | ||
return nil | ||
} | ||
|
||
func (t OffsetTime) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(t.String()) | ||
} | ||
|
||
func SplitTime(t time.Time) (LocalDate, OffsetTime) { | ||
return NewLocalDate(t), NewOffsetTime(t) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestSplitTime(t *testing.T) { | ||
now := time.Now().Truncate(time.Second) | ||
d, ot := SplitTime(now) | ||
restored := ot.Time(d) | ||
|
||
if now != restored { | ||
t.Fatalf("Restored time does not match the original time: %v != %v", now, restored) | ||
return | ||
} | ||
} |
Oops, something went wrong.