| 267 | | public function getTimestampForCulture($date, $culture = null) |
|---|
| 268 | | { |
|---|
| 269 | | list($d, $m, $y) = $this->getDateForCulture($date, is_null($culture) ? $this->culture : $culture); |
|---|
| 270 | | |
|---|
| 271 | | return is_null($d) ? null : mktime(0, 0, 0, $m, $d, $y); |
|---|
| | 267 | public function getTimestampForCulture($dateTime, $culture = null) |
|---|
| | 268 | { |
|---|
| | 269 | list($day, $month, $year) = $this->getDateForCulture($dateTime, is_null($culture) ? $this->culture : $culture); |
|---|
| | 270 | list($hour, $minute) = $this->getTimeForCulture($dateTime, is_null($culture) ? $this->culture : $culture); |
|---|
| | 271 | |
|---|
| | 272 | return is_null($day) ? null : mktime($hour, $minute, 0, $month, $day, $year); |
|---|
| | 322 | * Returns the hour, minute from a date formatted with a given culture. |
|---|
| | 323 | * |
|---|
| | 324 | * @param string $date The formatted date as string |
|---|
| | 325 | * @param string $culture The culture |
|---|
| | 326 | * |
|---|
| | 327 | * @return array An array with the hour and minute |
|---|
| | 328 | */ |
|---|
| | 329 | public function getTimeForCulture($time, $culture) |
|---|
| | 330 | { |
|---|
| | 331 | if (!$time) return 0; |
|---|
| | 332 | |
|---|
| | 333 | $culture = is_null($culture) ? $this->culture : $culture; |
|---|
| | 334 | |
|---|
| | 335 | $timeFormatInfo = @sfDateTimeFormatInfo::getInstance($culture); |
|---|
| | 336 | $timeFormat = $timeFormatInfo->getShortTimePattern(); |
|---|
| | 337 | |
|---|
| | 338 | // We construct the regexp based on time format |
|---|
| | 339 | $timeRegexp = preg_replace(array('/[^hm:]+/i', '/[hm]+/i'), array('', '(\d+)'), $timeFormat); |
|---|
| | 340 | |
|---|
| | 341 | // We parse time format to see where things are (h, m) |
|---|
| | 342 | $a = array( |
|---|
| | 343 | 'h' => strpos($timeFormat, 'H') !== false ? strpos($timeFormat, 'H') : strpos($timeFormat, 'h'), |
|---|
| | 344 | 'm' => strpos($timeFormat, 'm') |
|---|
| | 345 | ); |
|---|
| | 346 | $tmp = array_flip($a); |
|---|
| | 347 | ksort($tmp); |
|---|
| | 348 | $i = 0; |
|---|
| | 349 | $c = array(); |
|---|
| | 350 | foreach ($tmp as $value) $c[++$i] = $value; |
|---|
| | 351 | $timePositions = array_flip($c); |
|---|
| | 352 | |
|---|
| | 353 | // We find all elements |
|---|
| | 354 | if (preg_match("~$timeRegexp~", $time, $matches)) |
|---|
| | 355 | { |
|---|
| | 356 | // We get matching timestamp |
|---|
| | 357 | return array($matches[$timePositions['h']], $matches[$timePositions['m']]); |
|---|
| | 358 | } |
|---|
| | 359 | else |
|---|
| | 360 | { |
|---|
| | 361 | return null; |
|---|
| | 362 | } |
|---|
| | 363 | } |
|---|
| | 364 | |
|---|
| | 365 | /** |
|---|