@@ -213,21 +213,28 @@ protected function transformFeature(array $feature): MobileNoteData {
213213 $ properties = $ feature ['properties ' ] ?? [];
214214 $ geometry = $ feature ['geometry ' ] ?? [];
215215
216- $ item = [
217- 'id ' => $ featureId ,
218- 'address ' => $ properties ['osoite ' ] ?? '' ,
219- 'reason ' => $ properties ['merkinSyy ' ]['value ' ] ?? '' ,
220- 'valid_from ' => $ this ->dateToTimestamp ($ properties ['voimassaoloAlku ' ] ?? NULL ),
221- 'valid_to ' => $ this ->dateToTimestamp ($ properties ['voimassaoloLoppu ' ] ?? NULL ),
222- 'time_range ' => $ properties ['kello ' ] ?? '' ,
223- 'created_at ' => $ this ->dateTimeToTimestamp ($ properties ['luontipvm ' ] ?? NULL ),
224- 'updated_at ' => $ this ->dateTimeToTimestamp ($ properties ['paivityspvm ' ] ?? NULL ),
225- 'address_info ' => $ properties ['osoitteenlisatieto ' ] ?? '' ,
226- 'sign_type ' => $ properties ['merkinLaatu ' ]['value ' ] ?? '' ,
227- 'additional_text ' => $ properties ['lisakilvenTeksti ' ] ?? '' ,
228- 'notes ' => $ properties ['huomautukset ' ] ?? '' ,
229- 'phone ' => $ properties ['puhelinnumero ' ] ?? '' ,
230- ];
216+ try {
217+ $ item = [
218+ 'id ' => $ featureId ,
219+ 'address ' => $ properties ['osoite ' ] ?? '' ,
220+ 'reason ' => $ properties ['merkinSyy ' ]['value ' ] ?? '' ,
221+ 'valid_from ' => $ this ->dateToTimestamp ($ properties ['voimassaoloAlku ' ] ?? NULL ),
222+ // We only get date string from mobilenote. We
223+ // add 24 hours to get the end timestamp.
224+ 'valid_to ' => $ this ->dateToTimestamp ($ properties ['voimassaoloLoppu ' ] ?? NULL ) + 86400 ,
225+ 'time_range ' => $ properties ['kello ' ] ?? '' ,
226+ 'created_at ' => $ this ->dateTimeToTimestamp ($ properties ['luontipvm ' ] ?? NULL ),
227+ 'updated_at ' => $ this ->dateTimeToTimestamp ($ properties ['paivityspvm ' ] ?? NULL ),
228+ 'address_info ' => $ properties ['osoitteenlisatieto ' ] ?? '' ,
229+ 'sign_type ' => $ properties ['merkinLaatu ' ]['value ' ] ?? '' ,
230+ 'additional_text ' => $ properties ['lisakilvenTeksti ' ] ?? '' ,
231+ 'notes ' => $ properties ['huomautukset ' ] ?? '' ,
232+ 'phone ' => $ properties ['puhelinnumero ' ] ?? '' ,
233+ ];
234+ }
235+ catch (\DateException $ e ) {
236+ throw new \InvalidArgumentException ("MobileNote: Invalid date " , previous: $ e );
237+ }
231238
232239 // Convert geometry to GeoJSON object.
233240 if (!empty ($ geometry ['coordinates ' ])) {
@@ -252,17 +259,15 @@ protected function transformFeature(array $feature): MobileNoteData {
252259 *
253260 * @return int|null
254261 * The timestamp or NULL.
262+ *
263+ * @throws \DateException
255264 */
256265 protected function dateToTimestamp (?string $ dateString ): ?int {
257266 if (empty ($ dateString )) {
258- return NULL ;
259- }
260- try {
261- return (new \DateTime ($ dateString ))->getTimestamp ();
262- }
263- catch (\DateMalformedStringException ) {
264- return NULL ;
267+ throw new \DateMalformedStringException ('Empty date string ' );
265268 }
269+
270+ return (new \DateTime ($ dateString , new \DateTimeZone ('Europe/Helsinki ' )))->getTimestamp ();
266271 }
267272
268273 /**
@@ -279,9 +284,9 @@ protected function dateTimeToTimestamp(?string $dateTimeString): ?int {
279284 return NULL ;
280285 }
281286 try {
282- return (new \DateTime ($ dateTimeString ))->getTimestamp ();
287+ return (new \DateTime ($ dateTimeString, new \ DateTimeZone ( ' Europe/Helsinki ' ) ))->getTimestamp ();
283288 }
284- catch (\DateMalformedStringException ) {
289+ catch (\DateException ) {
285290 return NULL ;
286291 }
287292 }
0 commit comments