| 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); |
|---|
| | 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(array('/[^hm:]+/i', '/[hm]+/i'), array('', '(\d+)'), $timeFormat); |
|---|
| | 210 | |
|---|
| | 211 | // We parse time format to see where things are (h, m) |
|---|
| | 212 | $a = array( |
|---|
| | 213 | 'h' => strpos($timeFormat, 'H') !== false ? strpos($timeFormat, '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 | } |
|---|