1. sfWidgetFormI18nTime.class.php
  2. /** * sfWidgetFormI18nTime represents a time widget. * * @package symfony * @subpackage widget * @author Fabien Potencier * @version SVN: $Id: sfWidgetFormI18nTime.class.php 9046 2008-05-19 08:13:51Z FabianLange $ */
  3. class sfWidgetFormI18nTime extends sfWidgetFormTime
  4. {
  5. /**
  6. * Constructor.
  7. *
  8. * Available options:
  9. *
  10. * * culture: The culture to use for internationalized strings (required)
  11. *
  12. * @param array $options An array of options
  13. * @param array $attributes An array of default HTML attributes
  14. *
  15. * @see sfWidgetFormTime
  16. */
  17. protected function configure($options = array(), $attributes = array())
  18. {
  19. parent::configure($options, $attributes);
  20. $this->addRequiredOption('culture');
  21. $culture = isset($options['culture']) ? $options['culture'] : 'en';
  22. // format
  23. $this->setOption('format', $this->getTimeFormat($culture, true));
  24. // format_without_seconds
  25. $this->setOption('format_without_seconds', $this->getTimeFormat($culture, false));
  26. }
  27. protected function getTimeFormat($culture, $withSeconds)
  28. {
  29. $timeFormat = $withSeconds ? sfDateTimeFormatInfo::getInstance($culture)->getMediumTimePattern() : sfDateTimeFormatInfo::getInstance($culture)->getShortTimePattern();
  30. if (false === ($hourPos = stripos($timeFormat, 'h')) || false === ($minutePos = stripos($timeFormat, 'm')))
  31. {
  32. return $this->getOption('format');
  33. }
  34. $trans = array(
  35. substr($timeFormat, $hourPos, strripos($timeFormat, 'h') - $hourPos + 1) => '%hour%',
  36. substr($timeFormat, $minutePos, strripos($timeFormat, 'm') - $minutePos + 1) => '%minute%',
  37. );
  38. if ($withSeconds)
  39. {
  40. if (false === $secondPos = stripos($timeFormat, 's'))
  41. {
  42. return $this->getOption('format');
  43. }
  44. $trans[substr($timeFormat, $secondPos, strripos($timeFormat, 's') - $secondPos + 1)] = '%second%';
  45. }
  46. return strtr($timeFormat, $trans);
  47. }
  48. }

Debug toolbar