tplaner / When

PHP Date Recursion library

Home Page:https://github.com/tplaner/When

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Timezone not preserved from constructor

coatesap opened this issue · comments

In the following code, the timezone parameter seems to get ignored, and all recurrences inherit the system's default timezone (Europe/Paris in this example):

$timezone = new DateTimeZone('Asia/Tokyo');
$recurrence = new \When\When("today 10:00:00", $timezone);
$recurrence
        ->freq("daily")
        ->byday("mo,tu,we,th")
        ->byhour("10,11,12,13,14,15,16,17,18")
        ->byminute('00')
        ->bysecond('00')
        ->count(50)
        ->generateOccurrences();
var_dump($recurrence->occurrences);

Output:

array (size=9)
0 => 
    object(DateTime)[8]
        public 'date' => string '2015-08-25 10:00:00' (length=19)
        public 'timezone_type' => int 3
        public 'timezone' => string 'Europe/Paris' (length=12)
1 => 
    object(DateTime)[9]
        public 'date' => string '2015-08-25 11:00:00' (length=19)
        public 'timezone_type' => int 3
        public 'timezone' => string 'Europe/Paris' (length=12)
...

There seems to be a simple fix for this, which I'll submit shortly.