Ignore:
Timestamp:
Jan 21, 2011 11:50:07 AM (2 years ago)
Author:
thomasb
Message:

Use improved strtotime() function + reduce duplicated code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/main.inc

    r4424 r4439  
    979979 
    980980/** 
     981 * Improved equivalent to strtotime() 
     982 * 
     983 * @param string Date string 
     984 * @return int  
     985 */ 
     986function rcube_strtotime($date) 
     987{ 
     988  // check for MS Outlook vCard date format YYYYMMDD 
     989  if (preg_match('/^([12][90]\d\d)([01]\d)(\d\d)$/', trim($date), $matches)) { 
     990    return mktime(0,0,0, intval($matches[2]), intval($matches[3]), intval($matches[1])); 
     991  } 
     992  else if (is_numeric($date)) 
     993    return $date; 
     994 
     995  // support non-standard "GMTXXXX" literal 
     996  $date = preg_replace('/GMT\s*([+-][0-9]+)/', '\\1', $date); 
     997 
     998  // if date parsing fails, we have a date in non-rfc format. 
     999  // remove token from the end and try again 
     1000  while ((($ts = @strtotime($date)) === false) || ($ts < 0)) { 
     1001    $d = explode(' ', $date); 
     1002    array_pop($d); 
     1003    if (!$d) break; 
     1004    $date = implode(' ', $d); 
     1005  } 
     1006 
     1007  return $ts; 
     1008} 
     1009 
     1010 
     1011/** 
    9811012 * Convert the given date to a human readable form 
    9821013 * This uses the date formatting properties from config 
     
    9921023  $ts = NULL; 
    9931024 
    994   if (is_numeric($date)) 
    995     $ts = $date; 
    996   else if (!empty($date)) 
    997     { 
    998     // support non-standard "GMTXXXX" literal 
    999     $date = preg_replace('/GMT\s*([+-][0-9]+)/', '\\1', $date); 
    1000     // if date parsing fails, we have a date in non-rfc format. 
    1001     // remove token from the end and try again 
    1002     while ((($ts = @strtotime($date))===false) || ($ts < 0)) 
    1003       { 
    1004         $d = explode(' ', $date); 
    1005         array_pop($d); 
    1006         if (!$d) break; 
    1007         $date = implode(' ', $d); 
    1008       } 
    1009     } 
     1025  if (!empty($date)) 
     1026    $ts = rcube_strtotime($date); 
    10101027 
    10111028  if (empty($ts)) 
Note: See TracChangeset for help on using the changeset viewer.