Skip to content

Commit 16c06cf

Browse files
committed
Add 25 hours to valid_to timestamp
Valid to from api is only a date. We must assume that the item is valid to the end of the date.
1 parent 869e85a commit 16c06cf

1 file changed

Lines changed: 29 additions & 22 deletions

File tree

public/modules/custom/helfi_kymp_content/src/MobileNoteDataService.php

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -213,21 +213,30 @@ 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+
if (empty($properties['voimassaoloAlku']) || empty($properties['voimassaoloLoppu'])) {}
217+
218+
try {
219+
$item = [
220+
'id' => $featureId,
221+
'address' => $properties['osoite'] ?? '',
222+
'reason' => $properties['merkinSyy']['value'] ?? '',
223+
'valid_from' => $this->dateToTimestamp($properties['voimassaoloAlku'] ?? NULL),
224+
// We only get date string from mobilenote. We
225+
// add 25 hours to get the end timestamp.
226+
'valid_to' => $this->dateToTimestamp($properties['voimassaoloLoppu'] ?? NULL) + 86400 + 3600,
227+
'time_range' => $properties['kello'] ?? '',
228+
'created_at' => $this->dateTimeToTimestamp($properties['luontipvm'] ?? NULL),
229+
'updated_at' => $this->dateTimeToTimestamp($properties['paivityspvm'] ?? NULL),
230+
'address_info' => $properties['osoitteenlisatieto'] ?? '',
231+
'sign_type' => $properties['merkinLaatu']['value'] ?? '',
232+
'additional_text' => $properties['lisakilvenTeksti'] ?? '',
233+
'notes' => $properties['huomautukset'] ?? '',
234+
'phone' => $properties['puhelinnumero'] ?? '',
235+
];
236+
}
237+
catch (\DateMalformedStringException $e) {
238+
throw new \InvalidArgumentException("MobileNote: Invalid date", previous: $e);
239+
}
231240

232241
// Convert geometry to GeoJSON object.
233242
if (!empty($geometry['coordinates'])) {
@@ -252,17 +261,15 @@ protected function transformFeature(array $feature): MobileNoteData {
252261
*
253262
* @return int|null
254263
* The timestamp or NULL.
264+
*
265+
* @throws \DateMalformedStringException
255266
*/
256267
protected function dateToTimestamp(?string $dateString): ?int {
257268
if (empty($dateString)) {
258-
return NULL;
259-
}
260-
try {
261-
return (new \DateTime($dateString))->getTimestamp();
262-
}
263-
catch (\DateMalformedStringException) {
264-
return NULL;
269+
throw new \DateMalformedStringException('Empty date string');
265270
}
271+
272+
return (new \DateTime($dateString))->getTimestamp();
266273
}
267274

268275
/**

0 commit comments

Comments
 (0)