Skip to content

Commit

Permalink
Merge pull request #11 from airheartdev/feature/change-arrival-depart…
Browse files Browse the repository at this point in the history
…ure-times-to-method-with-correct-zone

Change ArrivingAt and DepartingAt to methods that use zone
  • Loading branch information
ivanvanderbyl authored Jun 21, 2022
2 parents d73a01e + 1afaa14 commit 052475e
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 40 deletions.
4 changes: 2 additions & 2 deletions duffel.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ type (
Distance Distance `json:"distance,omitempty"`
DestinationTerminal string `json:"destination_terminal"`
Destination Location `json:"destination"`
DepartingAt DateTime `json:"departing_at"`
ArrivingAt DateTime `json:"arriving_at"`
RawDepartingAt string `json:"departing_at"`
RawArrivingAt string `json:"arriving_at"`
Aircraft Aircraft `json:"aircraft"`
}

Expand Down
20 changes: 14 additions & 6 deletions examples/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,15 @@ func main() {

for _, slice := range offer.Slices {
for _, segment := range slice.Segments {
dep, _ := segment.DepartingAt()
arr, _ := segment.ArrivingAt()
t.AppendRow(table.Row{
slice.ID,
segment.Origin.IATACode,
segment.Destination.IATACode,
time.Time(segment.DepartingAt).Format(time.RFC822),
time.Time(segment.ArrivingAt).Format(time.RFC822),

dep.Format(time.RFC822),
arr.Format(time.RFC822),
segment.Passengers[0].CabinClass.String(),
renderChangeableStatus(slice),
})
Expand Down Expand Up @@ -209,25 +212,30 @@ func main() {

for _, slice := range offer.Slices.Add {
for _, segment := range slice.Segments {
dep, _ := segment.DepartingAt()
arr, _ := segment.ArrivingAt()

t.AppendRow(table.Row{
fmt.Sprintf("Add %s", slice.ID),
segment.Origin.IATACode,
segment.Destination.IATACode,
time.Time(segment.DepartingAt).Format(time.RFC822),
time.Time(segment.ArrivingAt).Format(time.RFC822),
dep.Format(time.RFC822),
arr.Format(time.RFC822),
// segment.Passengers != nil && segment.Passengers[0].CabinClass.String(),
renderChangeableStatus(slice),
})
}
}
for _, slice := range offer.Slices.Remove {
for _, segment := range slice.Segments {
dep, _ := segment.DepartingAt()
arr, _ := segment.ArrivingAt()
t.AppendRow(table.Row{
fmt.Sprintf("Remove %s", slice.ID),
segment.Origin.IATACode,
segment.Destination.IATACode,
time.Time(segment.DepartingAt).Format(time.RFC822),
time.Time(segment.ArrivingAt).Format(time.RFC822),
dep.Format(time.RFC822),
arr.Format(time.RFC822),
segment.Passengers[0].CabinClass.String(),
renderChangeableStatus(slice),
})
Expand Down
5 changes: 4 additions & 1 deletion examples/offer-requests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ func main() {
fmt.Printf(" 🛫 %s to %s\n", *s.Origin.CityName, *s.Destination.CityName)

for _, f := range s.Segments {
fmt.Printf(" Departing at %s • Arriving at %s\n", f.DepartingAt, f.ArrivingAt)
dep, _ := f.DepartingAt()
arr, _ := f.ArrivingAt()

fmt.Printf(" Departing at %s • Arriving at %s\n", dep, arr)
}

fmt.Printf(" 🛬 %s • %s\n", s.FareBrandName, time.Duration(s.Duration).String())
Expand Down
31 changes: 31 additions & 0 deletions flight.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package duffel

import "time"

func (f *Flight) DepartingAt() (time.Time, error) {
loc, err := time.LoadLocation(f.Origin.TimeZone)
if err != nil {
return time.Time{}, err
}

t, err := time.ParseInLocation("2006-01-02T15:04:05", f.RawDepartingAt, loc)
if err != nil {
return time.Time{}, err
}

return t, err
}

func (f *Flight) ArrivingAt() (time.Time, error) {
loc, err := time.LoadLocation(f.Destination.TimeZone)
if err != nil {
return time.Time{}, err
}

t, err := time.ParseInLocation("2006-01-02T15:04:05", f.RawArrivingAt, loc)
if err != nil {
return time.Time{}, err
}

return t, err
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ require (
github.com/cockroachdb/apd/v3 v3.0.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/elastic/go-licenser v0.4.0 // indirect
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
Expand Down
30 changes: 0 additions & 30 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/elastic/go-licenser v0.4.0 h1:jLq6A5SilDS/Iz1ABRkO6BHy91B9jBora8FwGRsDqUI=
github.com/elastic/go-licenser v0.4.0/go.mod h1:V56wHMpmdURfibNBggaSBfqgPxyT1Tldns1i87iTEvU=
github.com/gocarina/gocsv v0.0.0-20220520193141-bb9bebb918c3 h1:Cs2c2+FTKl8Ngpp0jQezzTgRnX4Wd2A0YxYgigyoQB8=
github.com/gocarina/gocsv v0.0.0-20220520193141-bb9bebb918c3/go.mod h1:5YoVOkjYAQumqlV356Hj3xeYh4BdZuLE0/nRkf2NKkI=
github.com/gorilla/schema v1.2.0 h1:YufUaxZYCKGFuAq3c96BOhjgd5nmXiOY9NGzF247Tsc=
Expand Down Expand Up @@ -57,42 +55,14 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f h1:hEYJvxw1lSnWIl8X9ofsYMklzaDs90JI2az5YMd4fPM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211102192858-4dd72447c267/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65 h1:M73Iuj3xbbb9Uk1DYhzydthsj6oOd6l9bpuFcNoUvTs=
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
10 changes: 10 additions & 0 deletions offerrequests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ func TestGetOfferRequest(t *testing.T) {
a.Equal("airport", data.Offers[0].Slices[0].DestinationType)
a.Equal(false, data.Offers[0].Slices[0].Changeable)
a.Equal("Refundable Main Cabin", data.Offers[0].Slices[0].FareBrandName)

// Assert that departing at is in the correct timezone
dep, err := data.Offers[0].Slices[0].Segments[0].DepartingAt()
a.NoError(err)
est, _ := time.LoadLocation("America/New_York")
a.True(dep.Equal(time.Date(2021, time.December, 30, 8, 55, 0, 0, est)), "Departure time should be in EST")

arr, err := data.Offers[0].Slices[0].Segments[0].ArrivingAt()
a.NoError(err)
a.True(arr.Equal(time.Date(2021, time.December, 30, 12, 07, 0, 0, est)), "Arrival time should be in EST")
}

func TestListOfferRequests(t *testing.T) {
Expand Down

0 comments on commit 052475e

Please sign in to comment.