@@ -114,7 +114,7 @@ public function backend(string $action): void
114
114
));
115
115
}
116
116
117
- /**
117
+ /**
118
118
* @param DateTime|null $start
119
119
* @param DateTime|null $end
120
120
*
@@ -123,17 +123,36 @@ public function backend(string $action): void
123
123
* @throws Exception\AccessDeniedException
124
124
* @throws Exception\ClientRequestException
125
125
*/
126
+
126
127
public function history (?DateTime $ start = null , ?DateTime $ end = null ): array
127
128
{
128
- $ songHistoryDataArray = $ this ->request ('GET ' , sprintf (
129
- 'station/%s/history ' ,
130
- $ this ->stationId
131
- ));
129
+ $ queryParams = [];
130
+
131
+ // Only add "start" if we actually have a DateTime object
132
+ if ($ start instanceof DateTime) {
133
+ // Adjust the format string to what your API expects
134
+ $ queryParams ['start ' ] = $ start ->format ('Y-m-d H:i:s ' );
135
+ }
136
+
137
+ // Only add "end" if we actually have a DateTime object
138
+ if ($ end instanceof DateTime) {
139
+ $ queryParams ['end ' ] = $ end ->format ('Y-m-d H:i:s ' );
140
+ }
141
+
142
+ $ queryString = http_build_query ($ queryParams );
143
+
144
+ $ endpoint = sprintf ('station/%s/history ' , $ this ->stationId );
145
+ if (!empty ($ queryString )) {
146
+ $ endpoint .= '? ' . $ queryString ;
147
+ }
148
+
149
+ $ songHistoryDataArray = $ this ->request ('GET ' , $ endpoint );
132
150
133
151
$ songHistory = [];
134
152
foreach ($ songHistoryDataArray as $ songHistoryData ) {
135
153
$ songHistory [] = Dto \SongHistoryDto::fromArray ($ songHistoryData );
136
154
}
155
+
137
156
return $ songHistory ;
138
157
}
139
158
0 commit comments