Enforce local time for birthday and anniversary fields

This commit is contained in:
Thomas Bruederli 2012-05-23 15:39:53 +02:00
parent eca8ebafc3
commit 7d1882ad76
2 changed files with 6 additions and 6 deletions

View file

@ -64,13 +64,13 @@ abstract class kolab_format
* Convert the given date/time value into a cDateTime object
*
* @param mixed Date/Time value either as unix timestamp, date string or PHP DateTime object
* @param DateTimeZone The timezone the date/time is in. Use global default if empty
* @param DateTimeZone The timezone the date/time is in. Use global default if Null, local time if False
* @param boolean True of the given date has no time component
* @return object The libkolabxml date/time object
*/
public static function get_datetime($datetime, $tz = null, $dateonly = false)
{
if (!$tz) $tz = self::$timezone;
if (!$tz && $tz !== false) $tz = self::$timezone;
$result = new cDateTime();
// got a unix timestamp (in UTC)
@ -79,7 +79,7 @@ abstract class kolab_format
if ($tz) $datetime->setTimezone($tz);
}
else if (is_string($datetime) && strlen($datetime))
$datetime = new DateTime($datetime, $tz);
$datetime = new DateTime($datetime, $tz ?: null);
if (is_a($datetime, 'DateTime')) {
$result->setDate($datetime->format('Y'), $datetime->format('n'), $datetime->format('j'));
@ -89,7 +89,7 @@ abstract class kolab_format
if ($tz && $tz->getName() == 'UTC')
$result->setUTC(true);
else if ($tz)
else if ($tz !== false)
$result->setTimezone($tz->getName());
}

View file

@ -233,9 +233,9 @@ class kolab_format_contact extends kolab_format
if (isset($object['freebusyurl']))
$this->obj->setFreeBusyUrl($object['freebusyurl']);
if (isset($object['birthday']))
$this->obj->setBDay(self::get_datetime($object['birthday'], null, true));
$this->obj->setBDay(self::get_datetime($object['birthday'], false, true));
if (isset($object['anniversary']))
$this->obj->setAnniversary(self::get_datetime($object['anniversary'], null, true));
$this->obj->setAnniversary(self::get_datetime($object['anniversary'], false, true));
if (!empty($object['photo'])) {
if ($type = rc_image_content_type($object['photo']))