|
@@ 653-662 (lines=10) @@
|
| 650 |
|
|
| 651 |
|
public function asStructuredData(string $format = 'H:i', $timezone = null): array |
| 652 |
|
{ |
| 653 |
|
$regularHours = $this->flatMap(function (OpeningHoursForDay $openingHoursForDay, string $day) use ($format, $timezone) { |
| 654 |
|
return $openingHoursForDay->map(function (TimeRange $timeRange) use ($format, $timezone, $day) { |
| 655 |
|
return [ |
| 656 |
|
'@type' => 'OpeningHoursSpecification', |
| 657 |
|
'dayOfWeek' => ucfirst($day), |
| 658 |
|
'opens' => $timeRange->start()->format($format, $timezone), |
| 659 |
|
'closes' => $timeRange->end()->format($format, $timezone), |
| 660 |
|
]; |
| 661 |
|
}); |
| 662 |
|
}); |
| 663 |
|
|
| 664 |
|
$exceptions = $this->flatMapExceptions(function (OpeningHoursForDay $openingHoursForDay, string $date) use ($format, $timezone) { |
| 665 |
|
if ($openingHoursForDay->isEmpty()) { |
|
@@ 677-685 (lines=9) @@
|
| 674 |
|
]]; |
| 675 |
|
} |
| 676 |
|
|
| 677 |
|
return $openingHoursForDay->map(function (TimeRange $timeRange) use ($format, $date, $timezone) { |
| 678 |
|
return [ |
| 679 |
|
'@type' => 'OpeningHoursSpecification', |
| 680 |
|
'opens' => $timeRange->start()->format($format, $timezone), |
| 681 |
|
'closes' => $timeRange->end()->format($format, $timezone), |
| 682 |
|
'validFrom' => $date, |
| 683 |
|
'validThrough' => $date, |
| 684 |
|
]; |
| 685 |
|
}); |
| 686 |
|
}); |
| 687 |
|
|
| 688 |
|
return array_merge($regularHours, $exceptions); |