Changeset 3127847 in github


Ignore:
Timestamp:
Jan 21, 2011 11:50:07 AM (2 years ago)
Author:
thomascube <thomas@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
26e76df
Parents:
58b5dde
Message:

Use improved strtotime() function + reduce duplicated code

Location:
program/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • program/include/main.inc

    r0501b63 r3127847  
    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)) 
  • program/include/rcube_imap_generic.php

    rf5e7b353 r3127847  
    32243224    private function strToTime($date) 
    32253225    { 
    3226         // support non-standard "GMTXXXX" literal 
    3227         $date = preg_replace('/GMT\s*([+-][0-9]+)/', '\\1', $date); 
    3228         // if date parsing fails, we have a date in non-rfc format. 
    3229         // remove token from the end and try again 
    3230         while ((($ts = @strtotime($date))===false) || ($ts < 0)) { 
    3231             $d = explode(' ', $date); 
    3232             array_pop($d); 
    3233             if (!$d) { 
    3234                 break; 
    3235             } 
    3236             $date = implode(' ', $d); 
    3237         } 
    3238  
    3239         $ts = (int) $ts; 
    3240  
     3226        $ts = (int) rcube_strtotime($date); 
    32413227        return $ts < 0 ? 0 : $ts; 
    32423228    } 
Note: See TracChangeset for help on using the changeset viewer.