thomascube
2012-03-14 a621a9d7ecf334c4894ef8f5168eb6208e5ae0e4
Accept DateTime object as input to format_date()

1 files modified
12 ■■■■ changed files
program/include/main.inc 12 ●●●● patch | view | raw | blame | history
program/include/main.inc
@@ -725,7 +725,7 @@
 * Convert the given date to a human readable form
 * This uses the date formatting properties from config
 *
 * @param mixed  Date representation (string or timestamp)
 * @param mixed  Date representation (string, timestamp or DateTime object)
 * @param string Date format to use
 * @param bool   Enables date convertion according to user timezone
 *
@@ -734,6 +734,13 @@
function format_date($date, $format=NULL, $convert=true)
{
  global $RCMAIL, $CONFIG;
  if (is_a($date, 'DateTime')) {
    $ts = $date->format('U');
    $tzs = $date->getTimezone();
  }
  else {
    $tzs = 'GMT';
  if (!empty($date))
    $ts = rcube_strtotime($date);
@@ -747,11 +754,12 @@
  catch (Exception $e) {
    return '';
  }
  }
  try {
    // convert to the right timezone
    $stz = date_default_timezone_get();
    $tz = new DateTimeZone($convert ? $RCMAIL->config->get('timezone') : 'GMT');
    $tz = new DateTimeZone($convert ? $RCMAIL->config->get('timezone') : $tzs);
    $date->setTimezone($tz);
    date_default_timezone_set($tz->getName());