Skip to content

Commit

Permalink
get locode: support the most widely used format.
Browse files Browse the repository at this point in the history
The format of "XX YYY" as well as "XXYYY" now supported for Get calls.

Signed-off-by: Ekaterina Pavlova <[email protected]>
  • Loading branch information
AliceInHunterland committed Nov 10, 2023
1 parent 205b818 commit a2c4e00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion pkg/locodedb/calls.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ func Get(locodeStr string) (Record, error) {
return Record{}, err
}

key, err := NewKey(locodeStr[:2], locodeStr[2:])
country := locodeStr[:2]
location := locodeStr[2:]

if len(locodeStr) == 6 {
location = locodeStr[3:]
}

key, err := NewKey(country, location)
if err != nil {
return Record{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/locodedb/calls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestGet(t *testing.T) {
})

t.Run("locode", func(t *testing.T) {
rec, err := locodedb.Get("RUMOW")
rec, err := locodedb.Get("RU MOW")
require.NoError(t, err)

require.Equal(t, rec.Country, "Russia")
Expand Down

0 comments on commit a2c4e00

Please sign in to comment.