Repository: googlemaps/google-maps-services-go (go)

Issue:
Client.PlaceDetails fails for ID ChIJUXcBoFD-nkcR3s74TnqlDHM
in v1.4.0 it fails with
**json: cannot unmarshal array into Go struct field PlaceDetailsResult.result.secondary_opening_hours of type maps.OpeningHours**

commit d757700d4eb9a15a3faa7af90c61d8270e2f8333 added SecondaryOpeningHours as an object:
SecondaryOpeningHours OpeningHours `json:"secondary_opening_hours,omitempty"`

it should be an array imho
SecondaryOpeningHours []*OpeningHours `json:"secondary_opening_hours,omitempty"`

In ID ChIJUXcBoFD-nkcR3s74TnqlDHM it is an array: "secondary_opening_hours" : [{...}]
and the comment says so too: "SecondaryOpeningHours may contain an array of entries ..."

It works in v1.3.2

Pull request:
fix: secondary opening hours parsing
This fixes parsing of secondary opening hours. 

Fixes #281 🦕

Patch:
diff --git a/places.go b/places.go
index e847b9e..5f867f4 100644
--- a/places.go
+++ b/places.go
@@ -404,7 +404,6 @@ func (r *PlaceDetailsRequest) params() url.Values {
 		q.Set("reviews_no_translations", "true")
 	}
 
-
 	if r.ReviewsSort != "" {
 		q.Set("reviews_sort", r.ReviewsSort)
 	}
@@ -514,7 +513,7 @@ type PlaceDetailsResult struct {
 	// or TAKEOUT) based on the types of the place. This field includes the
 	// special_days subfield of all hours, set for dates that have exceptional
 	// hours.
-	SecondaryOpeningHours *OpeningHours `json:"secondary_opening_hours,omitempty"`
+	SecondaryOpeningHours []OpeningHours `json:"secondary_opening_hours,omitempty"`
 	// PermanentlyClosed is a boolean flag indicating whether the place has permanently
 	// shut down (value true). If the place is not permanently closed, the flag is
 	// absent from the response.


Test patch:
diff --git a/places_test.go b/places_test.go
index cd47ce7..469671a 100644
--- a/places_test.go
+++ b/places_test.go
@@ -727,6 +727,63 @@ func TestPlaceDetails(t *testing.T) {
                 "Sunday: 12:00 – 8:45 PM"
             ]
         },
+		"secondary_opening_hours": [
+            {
+                "open_now": true,
+                "periods": [
+                    {
+                        "close": {
+                            "day": 0,
+                            "time": "2045"
+                        },
+                        "open": {
+                            "day": 0,
+                            "time": "1200"
+                        }
+                    },
+                    {
+                        "close": {
+                            "day": 4,
+                            "time": "2045"
+                        },
+                        "open": {
+                            "day": 4,
+                            "time": "1800"
+                        }
+                    },
+                    {
+                        "close": {
+                            "day": 5,
+                            "time": "2045"
+                        },
+                        "open": {
+                            "day": 5,
+                            "time": "1800"
+                        }
+                    },
+                    {
+                        "close": {
+                            "day": 6,
+                            "time": "2045"
+                        },
+                        "open": {
+                            "day": 6,
+                            "time": "1200"
+                        }
+                    }
+                ],
+                "type": "KITCHEN",
+                "weekday_text": [
+                    "Monday: 11:30 AM – 2:00 PM, 5:00 – 10:00 PM",
+                    "Tuesday: 11:30 AM – 2:00 PM, 5:00 – 10:00 PM",
+                    "Wednesday: 11:30 AM – 2:00 PM, 5:00 – 10:00 PM",
+                    "Thursday: 11:30 AM – 2:00 PM, 5:00 – 10:00 PM",
+                    "Friday: 11:30 AM – 2:00 PM, 5:00 – 10:00 PM",
+                    "Saturday: 11:30 AM – 2:00 PM, 5:00 – 10:00 PM",
+                    "Sunday: 11:30 AM – 2:00 PM, 5:00 – 9:00 PM"
+                ]
+            }
+	    ],
         "place_id": "ChIJ4cQcDV2uEmsRMxTEHBIe9ZQ",
         "serves_dinner": true,
         "utc_offset": 660,
@@ -739,10 +796,10 @@ func TestPlaceDetails(t *testing.T) {
 	defer server.Close()
 	c, _ := NewClient(WithAPIKey(apiKey), WithBaseURL(server.URL))
 	placeID := "ChIJ4cQcDV2uEmsRMxTEHBIe9ZQ"
-	fields := []PlaceDetailsFieldMask{PlaceDetailsFieldMaskBusinessStatus, PlaceDetailsFieldMaskDineIn, PlaceDetailsFieldMaskFormattedAddress, PlaceDetailsFieldMaskGeometry, PlaceDetailsFieldMaskName, PlaceDetailsFieldMaskCurrentOpeningHours, PlaceDetailsFieldMaskPlaceID, PlaceDetailsFieldMaskServesDinner, PlaceDetailsFieldMaskUTCOffset, PlaceDetailsFieldMaskWheelchairAccessibleEntrance}
+	fields := []PlaceDetailsFieldMask{PlaceDetailsFieldMaskBusinessStatus, PlaceDetailsFieldMaskDineIn, PlaceDetailsFieldMaskFormattedAddress, PlaceDetailsFieldMaskGeometry, PlaceDetailsFieldMaskName, PlaceDetailsFieldMaskCurrentOpeningHours, PlaceDetailsFieldMaskSecondaryOpeningHours, PlaceDetailsFieldMaskPlaceID, PlaceDetailsFieldMaskServesDinner, PlaceDetailsFieldMaskUTCOffset, PlaceDetailsFieldMaskWheelchairAccessibleEntrance}
 	r := &PlaceDetailsRequest{
 		PlaceID: placeID,
-		Fields: fields,
+		Fields:  fields,
 	}
 
 	resp, err := c.PlaceDetails(context.Background(), r)
@@ -779,6 +836,14 @@ func TestPlaceDetails(t *testing.T) {
 		t.Errorf("OpeningHours.Periods[0].Open.Time or Close.Time incorrect")
 	}
 
+	if resp.SecondaryOpeningHours[0].Periods[0].Open.Day != time.Sunday || resp.OpeningHours.Periods[0].Close.Day != time.Sunday {
+		t.Errorf("SecondaryOpeningHours[0].Periods[0].Open.Day or Close.Day incorrect")
+	}
+
+	if resp.SecondaryOpeningHours[0].Periods[0].Open.Time != "1200" || resp.OpeningHours.Periods[0].Close.Time != "2045" {
+		t.Errorf("SecondaryOpeningHours[0].Periods[0].Open.Time or Close.Time incorrect")
+	}
+
 	weekdayText := "Monday: Closed"
 	if weekdayText != resp.OpeningHours.WeekdayText[0] {
 		t.Errorf("expected %+v, was %+v", weekdayText, resp.OpeningHours.WeekdayText[0])