Changeset a621a9d in github


Ignore:
Timestamp:
Mar 14, 2012 5:33:05 PM (15 months ago)
Author:
thomascube <thomas@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.8
Children:
b9ce92d
Parents:
6699a68
Message:

Accept DateTime? object as input to format_date()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/include/main.inc

    r8f77c03 ra621a9d  
    726726 * This uses the date formatting properties from config 
    727727 * 
    728  * @param mixed  Date representation (string or timestamp) 
     728 * @param mixed  Date representation (string, timestamp or DateTime object) 
    729729 * @param string Date format to use 
    730730 * @param bool   Enables date convertion according to user timezone 
     
    736736  global $RCMAIL, $CONFIG; 
    737737 
    738   if (!empty($date)) 
    739     $ts = rcube_strtotime($date); 
    740  
    741   if (empty($ts)) 
    742     return ''; 
    743  
    744   try { 
    745     $date = new DateTime("@".$ts); 
    746   } 
    747   catch (Exception $e) { 
    748     return ''; 
     738  if (is_a($date, 'DateTime')) { 
     739    $ts = $date->format('U'); 
     740    $tzs = $date->getTimezone(); 
     741  } 
     742  else { 
     743    $tzs = 'GMT'; 
     744 
     745    if (!empty($date)) 
     746      $ts = rcube_strtotime($date); 
     747 
     748    if (empty($ts)) 
     749      return ''; 
     750 
     751    try { 
     752      $date = new DateTime("@".$ts); 
     753    } 
     754    catch (Exception $e) { 
     755      return ''; 
     756    } 
    749757  } 
    750758 
     
    752760    // convert to the right timezone 
    753761    $stz = date_default_timezone_get(); 
    754     $tz = new DateTimeZone($convert ? $RCMAIL->config->get('timezone') : 'GMT'); 
     762    $tz = new DateTimeZone($convert ? $RCMAIL->config->get('timezone') : $tzs); 
    755763    $date->setTimezone($tz); 
    756764    date_default_timezone_set($tz->getName()); 
Note: See TracChangeset for help on using the changeset viewer.