I’m creating an array from dates of a children collection with a page model. Each page has a start and an end date. After creating date objects some of them have GMT+1 and others have GMT+2. Even though the timezone is set…
date_default_timezone_set('Europe/Zurich');
The page model looks like:
public function bookedRange(array $rooms = null)
{
$dates = [];
$bookings = page('bookings')->children();
foreach ($bookings as $booking) {
$timezone = new DateTimeZone(date_default_timezone_get());
$start = new Date($booking->start()->toDate(),$timezone);
$end = new Date($booking->end()->toDate(),$timezone);
$now = new Date(Date('Y-m-d'));
$dates[] = [
'from' => $start,
'to' => $end,
'created' => $booking->published('%Y-%m-%d %H:%M:%S')
];
}
return $dates;
}
And it outputs the following array:
Array
(
[0] => Array
(
[from] => Kirby\Toolkit\Date Object
(
[date] => 2022-08-22 15:00:00.000000
[timezone_type] => 1
[timezone] => +02:00
)
[to] => Kirby\Toolkit\Date Object
(
[date] => 2022-08-28 10:00:00.000000
[timezone_type] => 1
[timezone] => +02:00
)
[created] => Kirby\Cms\Field Object
(
[published] =>
)
)
[1] => Array
(
[from] => Kirby\Toolkit\Date Object
(
[date] => 2022-09-19 15:00:00.000000
[timezone_type] => 1
[timezone] => +02:00
)
[to] => Kirby\Toolkit\Date Object
(
[date] => 2022-09-25 10:00:00.000000
[timezone_type] => 1
[timezone] => +02:00
)
[created] => Kirby\Cms\Field Object
(
[published] =>
)
)
[2] => Array
(
[from] => Kirby\Toolkit\Date Object
(
[date] => 2022-12-12 15:00:00.000000
[timezone_type] => 1
[timezone] => +01:00
)
[to] => Kirby\Toolkit\Date Object
(
[date] => 2022-12-25 10:00:00.000000
[timezone_type] => 1
[timezone] => +01:00
)
[created] => Kirby\Cms\Field Object
(
[published] =>
)
)
[3] => Array
(
[from] => Kirby\Toolkit\Date Object
(
[date] => 2022-08-28 15:00:00.000000
[timezone_type] => 1
[timezone] => +02:00
)
[to] => Kirby\Toolkit\Date Object
(
[date] => 2022-08-31 10:00:00.000000
[timezone_type] => 1
[timezone] => +02:00
)
[created] => Kirby\Cms\Field Object
(
[published] =>
)
)
[4] => Array
(
[from] => Kirby\Toolkit\Date Object
(
[date] => 2022-09-03 15:00:00.000000
[timezone_type] => 1
[timezone] => +02:00
)
[to] => Kirby\Toolkit\Date Object
(
[date] => 2022-09-04 10:00:00.000000
[timezone_type] => 1
[timezone] => +02:00
)
[created] => Kirby\Cms\Field Object
(
[published] =>
)
)
[5] => Array
(
[from] => Kirby\Toolkit\Date Object
(
[date] => 2022-10-10 15:00:00.000000
[timezone_type] => 1
[timezone] => +02:00
)
[to] => Kirby\Toolkit\Date Object
(
[date] => 2022-10-16 10:00:00.000000
[timezone_type] => 1
[timezone] => +02:00
)
[created] => Kirby\Cms\Field Object
(
[published] =>
)
)
[6] => Array
(
[from] => Kirby\Toolkit\Date Object
(
[date] => 2022-11-01 15:00:00.000000
[timezone_type] => 1
[timezone] => +01:00
)
[to] => Kirby\Toolkit\Date Object
(
[date] => 2022-11-06 10:00:00.000000
[timezone_type] => 1
[timezone] => +01:00
)
[created] => Kirby\Cms\Field Object
(
[published] =>
)
)
[7] => Array
(
[from] => Kirby\Toolkit\Date Object
(
[date] => 2022-09-10 15:00:00.000000
[timezone_type] => 1
[timezone] => +02:00
)
[to] => Kirby\Toolkit\Date Object
(
[date] => 2022-09-17 10:00:00.000000
[timezone_type] => 1
[timezone] => +02:00
)
[created] => Kirby\Cms\Field Object
(
[published] =>
)
)
[8] => Array
(
[from] => Kirby\Toolkit\Date Object
(
[date] => 2022-08-19 16:45:00.000000
[timezone_type] => 1
[timezone] => +02:00
)
[to] => Kirby\Toolkit\Date Object
(
[date] => 2022-08-22 16:45:00.000000
[timezone_type] => 1
[timezone] => +02:00
)
[created] => Kirby\Cms\Field Object
(
[published] =>
)
)
[9] => Array
(
[from] => Kirby\Toolkit\Date Object
(
[date] => 2022-08-02 22:30:00.000000
[timezone_type] => 1
[timezone] => +02:00
)
[to] => Kirby\Toolkit\Date Object
(
[date] => 2022-08-17 22:30:00.000000
[timezone_type] => 1
[timezone] => +02:00
)
[created] => Kirby\Cms\Field Object
(
[published] =>
)
)
)
Can someone help me to rule the timezones?
BTW: If I remove the timzone definition date_default_timezone_set('Europe/Zurich');
then it outputs for every time +00:00