Development

#2896: bug2896-bigmadwolf1.diff

You must first sign up to be able to contribute.

Ticket #2896: bug2896-bigmadwolf1.diff

File bug2896-bigmadwolf1.diff, 1.8 kB (added by BigMadWolf, 8 months ago)

Patch proposal

  • lib/i18n/sfI18N.class.php

    old new  
    154154  } 
    155155 
    156156  // Return timestamp from a date formatted with a given culture 
    157   public static function getTimestampForCulture($date, $culture) 
     157  public static function getTimestampForCulture($dateTime, $culture) 
    158158  { 
    159     list($d, $m, $y) = self::getDateForCulture($date, $culture); 
    160     return mktime(0, 0, 0, $m, $d, $y); 
     159    list($d, $m, $y) = self::getDateForCulture($dateTime, $culture); 
     160    list($h, $min) = self::getTimeForCulture($dateTime, $culture); 
     161    return mktime($h, $min, 0, $m, $d, $y); 
    161162  } 
    162163 
    163164  // Return a d, m and y from a date formatted with a given culture 
     
    195196      return null; 
    196197    } 
    197198  } 
     199 
     200  // Return h and m from a time formatted with a given culture 
     201  public static function getTimeForCulture($time, $culture) 
     202  { 
     203    if (!$time) return 0; 
     204 
     205    $timeFormatInfo = @sfDateTimeFormatInfo::getInstance($culture); 
     206    $timeFormat = $timeFormatInfo->getShortTimePattern(); 
     207 
     208    // We construct the regexp based on time format 
     209    $timeRegexp = preg_replace('/[hm]+/i', '(\d+)', $timeFormat); 
     210 
     211    // We parse time format to see where things are (h, m) 
     212    $a = array( 
     213      'h' => strpos($timeFormat, 'H'), 
     214      'm' => strpos($timeFormat, 'm') 
     215    ); 
     216    $tmp = array_flip($a); 
     217    ksort($tmp); 
     218    $i = 0; 
     219    $c = array(); 
     220    foreach ($tmp as $value) $c[++$i] = $value; 
     221    $timePositions = array_flip($c); 
     222 
     223    // We find all elements 
     224    if (preg_match("~$timeRegexp~", $time, $matches)) 
     225    { 
     226      // We get matching timestamp 
     227      return array($matches[$timePositions['h']], $matches[$timePositions['m']]); 
     228    } 
     229    else 
     230    { 
     231      return null; 
     232    } 
     233  } 
    198234}