| 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($date, $culture); |
|---|
| | 160 | list($hour, $minute) = self::getTimeForCulture($date, $culture); |
|---|
| | 161 | |
|---|
| | 162 | return mktime($hour, $minute, 0, $m, $d, $y); |
|---|
| | 200 | |
|---|
| | 201 | /** |
|---|
| | 202 | * Returns the hour, minute from a date formatted with a given culture. |
|---|
| | 203 | * |
|---|
| | 204 | * @param string $date The formatted date as string |
|---|
| | 205 | * @param string $culture The culture |
|---|
| | 206 | * |
|---|
| | 207 | * @return array An array with the hour and minute |
|---|
| | 208 | */ |
|---|
| | 209 | protected static function getTimeForCulture($time, $culture) |
|---|
| | 210 | { |
|---|
| | 211 | if (!$time) return 0; |
|---|
| | 212 | |
|---|
| | 213 | $culture = is_null($culture) ? $this->culture : $culture; |
|---|
| | 214 | |
|---|
| | 215 | $timeFormatInfo = @sfDateTimeFormatInfo::getInstance($culture); |
|---|
| | 216 | $timeFormat = $timeFormatInfo->getShortTimePattern(); |
|---|
| | 217 | |
|---|
| | 218 | // We construct the regexp based on time format |
|---|
| | 219 | $timeRegexp = preg_replace(array('/[^hm:]+/i', '/[hm]+/i'), array('', '(\d+)'), $timeFormat); |
|---|
| | 220 | |
|---|
| | 221 | // We parse time format to see where things are (h, m) |
|---|
| | 222 | $a = array( |
|---|
| | 223 | 'h' => strpos($timeFormat, 'H') !== false ? strpos($timeFormat, 'H') : strpos($timeFormat, 'h'), |
|---|
| | 224 | 'm' => strpos($timeFormat, 'm') |
|---|
| | 225 | ); |
|---|
| | 226 | $tmp = array_flip($a); |
|---|
| | 227 | ksort($tmp); |
|---|
| | 228 | $i = 0; |
|---|
| | 229 | $c = array(); |
|---|
| | 230 | |
|---|
| | 231 | foreach ($tmp as $value) |
|---|
| | 232 | { |
|---|
| | 233 | $c[++$i] = $value; |
|---|
| | 234 | } |
|---|
| | 235 | |
|---|
| | 236 | $timePositions = array_flip($c); |
|---|
| | 237 | |
|---|
| | 238 | // We find all elements |
|---|
| | 239 | if (preg_match("~$timeRegexp~", $time, $matches)) |
|---|
| | 240 | { |
|---|
| | 241 | // We get matching timestamp |
|---|
| | 242 | return array($matches[$timePositions['h']], $matches[$timePositions['m']]); |
|---|
| | 243 | } |
|---|
| | 244 | else |
|---|
| | 245 | { |
|---|
| | 246 | return null; |
|---|
| | 247 | } |
|---|
| | 248 | } |
|---|
| | 249 | |
|---|