-
Notifications
You must be signed in to change notification settings - Fork 1
/
destination.go
105 lines (90 loc) · 2.48 KB
/
destination.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package s7_api_sdk
import (
"fmt"
"time"
)
const (
longForm = "2006-01-02 15:04"
longFormT = "2006-01-02T15:04:05"
)
type OriginDestination struct {
Reference string `xml:"refs,attr,omitempty"`
SegmentKey string `xml:",omitempty"`
Status *Status `xml:",omitempty"`
Departure *Point `xml:",omitempty"`
Arrival *Point `xml:",omitempty"`
MarketingCarrier *Carrier `xml:",omitempty"`
OperatingCarrier *Carrier `xml:",omitempty"`
CalendarDates *CalendarDates `xml:",omitempty"`
Equipment *Equipment `xml:",omitempty"`
CabinType *StatusCode `xml:",omitempty"`
ClassOfService *ClassOfService `xml:",omitempty"`
Flight *Flight `xml:",omitempty"`
}
type Status struct {
StatusCode *StatusCode
}
type StatusCode struct {
Code string
}
type Point struct {
AirportCode string
Date string `xml:",omitempty"`
Time string `xml:",omitempty"`
Terminal *Terminal `xml:",omitempty"`
}
func (p *Point) GetTerminal() string {
if p.Terminal != nil {
return p.Terminal.Name
}
return ""
}
func (p *Point) GetDate() time.Time {
date, _ := time.Parse(longForm, fmt.Sprintf("%s %s", p.Date, p.Time))
return date
}
func (p *Point) GetDateISO() string {
return fmt.Sprintf("%sT%s", p.Date, p.Time)
}
type Terminal struct {
Name string
}
func MakePoint(namePoint, dataPoint, timePoint, terminal string) *Point {
p := &Point{
AirportCode: namePoint,
Date: dataPoint,
Time: timePoint,
}
if terminal != "" {
p.Terminal = &Terminal{
Name: terminal,
}
}
return p
}
func MakeOriginDestination(departureAirportCode string, dateDep time.Time, arrivalAirportCode string, dateArr time.Time, daysBefore, daysAfter int) *OriginDestination {
originDestination := new(OriginDestination)
originDestination.Departure = &Point{
AirportCode: departureAirportCode,
}
if dateDep.Year() != 1 {
originDestination.Departure.Date = dateDep.Format("2006-01-02")
}
originDestination.Arrival = &Point{
AirportCode: arrivalAirportCode,
}
if dateArr.Year() != 1 {
originDestination.Arrival.Date = dateArr.Format("2006-01-02")
}
if daysBefore > 0 || daysAfter > 0 {
originDestination.CalendarDates = &CalendarDates{
DaysBefore: daysBefore,
DaysAfter: daysAfter,
}
}
return originDestination
}
type OriginDestinationFlight struct {
OriginDestinationKey string `xml:",omitempty"`
Flight []*OriginDestination
}