|
@@ 673-682 (lines=10) @@
|
| 670 |
|
|
| 671 |
|
public function asStructuredData(string $format = 'H:i', $timezone = null): array |
| 672 |
|
{ |
| 673 |
|
$regularHours = $this->flatMap(function (OpeningHoursForDay $openingHoursForDay, string $day) use ($format, $timezone) { |
| 674 |
|
return $openingHoursForDay->map(function (TimeRange $timeRange) use ($format, $timezone, $day) { |
| 675 |
|
return [ |
| 676 |
|
'@type' => 'OpeningHoursSpecification', |
| 677 |
|
'dayOfWeek' => ucfirst($day), |
| 678 |
|
'opens' => $timeRange->start()->format($format, $timezone), |
| 679 |
|
'closes' => $timeRange->end()->format($format, $timezone), |
| 680 |
|
]; |
| 681 |
|
}); |
| 682 |
|
}); |
| 683 |
|
|
| 684 |
|
$exceptions = $this->flatMapExceptions(function (OpeningHoursForDay $openingHoursForDay, string $date) use ($format, $timezone) { |
| 685 |
|
if ($openingHoursForDay->isEmpty()) { |
|
@@ 697-705 (lines=9) @@
|
| 694 |
|
]]; |
| 695 |
|
} |
| 696 |
|
|
| 697 |
|
return $openingHoursForDay->map(function (TimeRange $timeRange) use ($format, $date, $timezone) { |
| 698 |
|
return [ |
| 699 |
|
'@type' => 'OpeningHoursSpecification', |
| 700 |
|
'opens' => $timeRange->start()->format($format, $timezone), |
| 701 |
|
'closes' => $timeRange->end()->format($format, $timezone), |
| 702 |
|
'validFrom' => $date, |
| 703 |
|
'validThrough' => $date, |
| 704 |
|
]; |
| 705 |
|
}); |
| 706 |
|
}); |
| 707 |
|
|
| 708 |
|
return array_merge($regularHours, $exceptions); |