DateTimeZone::__construct(): Unknown or bad timezone (PST8PDT)

1,719 views
Skip to first unread message

Chintan Shah

unread,
Jul 8, 2014, 2:14:27 AM7/8/14
to google-doubleclick...@googlegroups.com
Greetings, 

I am trying to execute "GetRecentlyUpdatedLineItems.php" sample from v201405 and getting fatal error, 
DateTimeZone::__construct(): Unknown or bad timezone (PST8PDT). I have not made any change to code.

Please help me on this.

--
Thanks,
Chintan Shah

Vincent Tsao (DFP API Team)

unread,
Jul 10, 2014, 9:32:09 AM7/10/14
to google-doubleclick...@googlegroups.com
Hi Chintan:

(1) What version of PHP are you using?
(2) What is your network code?

Thanks,
Vincent Tsao, DFP API Team

Chintan Shah

unread,
Jul 10, 2014, 11:26:07 AM7/10/14
to google-doubleclick...@googlegroups.com
Hi Vincent,

Thanks for the reply.

1) My PHP Version is 5.5.12 [I am using WAMP]
2) My Network code is 36533610.

--
Thanks,
Chintan Shah

Vincent Tsao (DFP API Team)

unread,
Jul 14, 2014, 1:01:08 PM7/14/14
to google-doubleclick...@googlegroups.com
Hey Chintan:

Sorry for the late reply on this, what order ID are you running the example with?

Thanks,
Vincent Tsao, DFP API Team


Chintan Shah

unread,
Jul 14, 2014, 1:05:16 PM7/14/14
to google-doubleclick...@googlegroups.com
Hi Vincent,

I have ignored the Order Id Criteria for that. I have change that line of $var by,
  $vars = MapUtils::GetMapEntries(array('threeDaysAgo' => new TextValue($threeDaysAgo)));


--
Thanks,
Chintan Shah

Vincent Tsao (DFP API Team)

unread,
Jul 14, 2014, 1:29:22 PM7/14/14
to google-doubleclick...@googlegroups.com
Hi Chintan:

This looks like a bug introduced in PHP 5.5.10:

PST8PDT is indeed a valid timezone. The PHP people are claiming it's not a bug, but seems like it is since it's breaking people. Since it's unclear whether PHP will fix it or not, we'll hold off making any changes to the PHP client library. In the meantime, you could do the following:

(1) Switch a version of PHP before 5.5.10. This is probably not ideal.
(2) Modify DateTimeUtils.php to map the PST8PDT timezone to a format that PHP 5.5.10 supports.
(3) Don't use DateTimeUtils.php in the example and just print out the parts of the DateTime object yourself, without creating a PHP date time object from it.

Thanks,
Vincent Tsao, DFP API Team

Chintan Shah

unread,
Jul 15, 2014, 11:36:27 AM7/15/14
to google-doubleclick...@googlegroups.com
Thank you Vincent for your help.

--
Thanks,
Chintan Shah

Marijus Plančiūnas

unread,
Jul 15, 2014, 12:34:16 PM7/15/14
to google-doubleclick...@googlegroups.com
I wrote a helper function for myself for this. It just translates "non-valid" (not supported) time zones to valid ones. It may be not very accurate - as I tried to Google for equivalents - so feel free to modify it.
DFP team - consider returning valid time zones please. PST8PDT is not a timezone at all, it's just an abbrevation for "America/Los_Angeles",- and abbrevations don't pay attention to daylight savings AFAIK. They were left for compatibility purposes for a long time...

Function, compatible with DFP classes:

function correctDFPTimeZoneId( DfpDateTime $datetime )
{
 $timezone_replacements
= [
 
'CST6CDT'   => 'America/Chicago',
 
'Cuba'      => 'Etc/GMT-5',
 
'Egypt'     => 'Etc/GMT+2',
 
'Eire'      => 'UTC',
 
'EST5EDT'   => 'America/New_York',
 
'Factory'   => 'UTC',
 
'GB-Eire'   => 'UTC',
 
'GMT0'      => 'UTC',
 
'Greenwich' => 'UTC',
 
'Hongkong'  => 'Etc/GMT+8',
 
'Iceland'   => 'UTC',
 
'Iran'      => 'Etc/GMT+3',
 
'Israel'    => 'Etc/GMT+2',
 
'Jamaica'   => 'Etc/GMT-5',
 
'Japan'     => 'Etc/GMT+9',
 
'Kwajalein' => 'Etc/GMT+12',
 
'Libya'     => 'Etc/GMT+2',
 
'MST7MDT'   => 'Etc/GMT-7',
 
'Navajo'    => 'Etc/GMT-7',
 
'NZ-CHAT'   => 'Etc/GMT+12',
 
'Poland'    => 'Etc/GMT+1',
 
'Portugal'  => 'UTC',
 
'PST8PDT'   => 'America/Los_Angeles',
 
'Singapore' => 'Etc/GMT+8',
 
'Turkey'    => 'Etc/GMT+2',
 
'Universal' => 'UTC',
 
'W-SU'      => 'Etc/GMT+4'
 
];

 
if ( isset( $timezone_replacements[ $datetime->timeZoneID ] ) )
 
{
 $datetime
->timeZoneID = $timezone_replacements[ $datetime->timeZoneID ];
 
}

 
return $datetime;
}


Usage is very simple:

$datetime = correctDFPTimeZoneId( $datetime );


Reply all
Reply to author
Forward
0 new messages