Search code examples
phptimezonepeardst

How to get timezone hour offset and account for DST with PEAR::Date?


I am trying to get the offset hours from UTC, given a summer date. My system time is set to America/Los_Angeles.

I have the following:

require_once("Date.php");

$dateTZ = new Date_TimeZone('America/Los_Angeles');

echo $dateTZ->getOffset(new Date('2009-07-01 12:00:00'))/1000/60/60;

This prints '-8'; shouldn't it show '-7'?

echo $dateTZ->getOffset(new Date())/1000/60/60;

also prints '-8'.

What am I doing wrong?


Solution

  • Does Date::inDaylightTime() help you? Date::getTZOffset claims to include daylight savings offset.