/**
  * Gets the era. i.e. in gregorian, year > 0 is AD, else BC.
  *
  * @todo How to support multiple Eras?, e.g. Japanese.
  * @param array   $date     getdate format.
  * @param string  $pattern  a pattern.
  * @return string era
  */
 protected function getEra($date, $pattern = 'G')
 {
     if ($pattern != 'G') {
         throw new sfException('The pattern for era is "G".');
     }
     return $this->formatInfo->getEra($date['year'] > 0 ? 1 : 0);
 }
 protected function getDateFormat($culture)
 {
     $dateFormat = sfDateTimeFormatInfo::getInstance($culture)->getShortDatePattern();
     if (false === ($dayPos = stripos($dateFormat, 'd')) || false === ($monthPos = stripos($dateFormat, 'm')) || false === ($yearPos = stripos($dateFormat, 'y'))) {
         return $this->getOption('format');
     }
     return strtr($dateFormat, array(substr($dateFormat, $dayPos, strripos($dateFormat, 'd') - $dayPos + 1) => '%day%', substr($dateFormat, $monthPos, strripos($dateFormat, 'm') - $monthPos + 1) => '%month%', substr($dateFormat, $yearPos, strripos($dateFormat, 'y') - $yearPos + 1) => '%year%'));
 }
 /**
  * Constructor.
  *
  * Available options:
  *
  *  * culture: The culture to use for internationalized strings (required)
  *
  * @param array $options     An array of options
  * @param array $attributes  An array of default HTML attributes
  *
  * @see sfWidgetFormDateTime
  */
 protected function configure($options = array(), $attributes = array())
 {
     parent::configure($options, $attributes);
     $this->addRequiredOption('culture');
     $culture = isset($options['culture']) ? $options['culture'] : 'en';
     // format
     $this->setOption('format', str_replace(array('{0}', '{1}'), array('%time%', '%date%'), sfDateTimeFormatInfo::getInstance($culture)->getDateTimeOrderPattern()));
 }
 protected function getDayFormat($culture, $dayFormat)
 {
     switch ($dayFormat) {
         case 'name':
             return array_combine(range(1, 7), sfDateTimeFormatInfo::getInstance($culture)->getDayNames());
         case 'short_name':
             return array_combine(range(1, 7), sfDateTimeFormatInfo::getInstance($culture)->getAbbreviatedDayNames());
         case 'number':
             return $this->getOption('days');
         default:
             throw new InvalidArgumentException(sprintf('The day format "%s" is invalid.', $dayFormat));
     }
 }
 protected function generateDayList()
 {
     $result = array();
     $dayNames = sfDateTimeFormatInfo::getInstance(sfContext::getInstance()->getUser()->getCulture())->getAbbreviatedDayNames();
     $sun = array_shift($dayNames);
     $dayNames[] = $sun;
     $day = opConfig::get('daily_news_day');
     $config = sfConfig::get('openpne_sns_config');
     $i18n = sfContext::getInstance()->getI18N();
     foreach ($day as $v) {
         $result[] = $i18n->__($config['daily_news_day']['Choices'][$v]);
     }
     return $result;
 }
Example #6
0
 protected function getTimeFormat($culture, $withSeconds)
 {
     $timeFormat = $withSeconds ? sfDateTimeFormatInfo::getInstance($culture)->getMediumTimePattern() : sfDateTimeFormatInfo::getInstance($culture)->getShortTimePattern();
     if (false === ($hourPos = stripos($timeFormat, 'h')) || false === ($minutePos = stripos($timeFormat, 'm'))) {
         return $this->getOption('format');
     }
     $trans = array(substr($timeFormat, $hourPos, strripos($timeFormat, 'h') - $hourPos + 1) => '%hour%', substr($timeFormat, $minutePos, strripos($timeFormat, 'm') - $minutePos + 1) => '%minute%');
     if ($withSeconds) {
         if (false === ($secondPos = stripos($timeFormat, 's'))) {
             return $this->getOption('format');
         }
         $trans[substr($timeFormat, $secondPos, strripos($timeFormat, 's') - $secondPos + 1)] = '%second%';
     }
     return strtr($timeFormat, $trans);
 }
Example #7
0
 public function executeDays($request)
 {
     $inputDate = $request->getParameter('date');
     // Check the input value and convert it to time
     if ($inputDate == '' || is_null($inputDate)) {
         $inputTime = time();
     } else {
         $inputTime = strtotime($inputDate);
         if ($inputTime == '') {
             $inputTime = time();
         }
     }
     $matrix = array();
     $dayNames = array();
     $matrixTotal = 1;
     $firstDayOfMonth = Datepicker::getFirstDayOfMonth($inputTime);
     if ($firstDayOfMonth == -1) {
         $firstDayOfMonth = 6;
     }
     for ($i = Datepicker::getPrevMonthMaxDays($inputTime) - $firstDayOfMonth; $i <= Datepicker::getPrevMonthMaxDays($inputTime); $i++) {
         $matrix[strtotime($i . '.' . Datepicker::getPrevMonth($inputTime) . '.' . Datepicker::getYearPrevMonth($inputTime))] = $i;
         $matrixTotal++;
     }
     for ($i = 1; $i <= date('t', $inputTime); $i++) {
         $matrix[strtotime($i . '.' . date('m', $inputTime) . '.' . date('Y', $inputTime))] = $i;
         $matrixTotal++;
     }
     if ($matrixTotal != 42) {
         for ($i = 1; $i <= 43 - $matrixTotal; $i++) {
             $matrix[strtotime($i . '.' . Datepicker::getNextMonth($inputTime) . '.' . Datepicker::getYearNextMonth($inputTime))] = $i;
         }
     }
     foreach (sfDateTimeFormatInfo::getInstance($this->getUser()->getCulture())->getDayNames() as $days) {
         $dayNames[] = ucfirst(substr($days, 0, 2));
     }
     $this->month_matrix = $matrix;
     $this->time = $inputTime;
     $this->dayNames = $dayNames;
 }
/**
 * Retrieves the proper date format based on the specified <i>$culture</i> setting
 *
 * <b>Note:</b> If no <i>$culture</i> is defined, the user's culture setting will be used in its place.
 *
 * @param  string two or three character culture setting variable
 * @return string formatted date/time format based on the specified date/time setting
 * @see sfUser
 */
function _get_I18n_date_locales($culture = null)
{
    if (!$culture) {
        $culture = sfContext::getInstance()->getUser()->getCulture();
    }
    $retval = array('culture' => $culture);
    $dateFormatInfo = sfDateTimeFormatInfo::getInstance($culture);
    $date_format = strtolower($dateFormatInfo->getShortDatePattern());
    $retval['dateFormatInfo'] = $dateFormatInfo;
    $match_pattern = "/([dmy]+)(.*?)([dmy]+)(.*?)([dmy]+)/";
    if (!preg_match($match_pattern, $date_format, $match_arr)) {
        // if matching fails use en shortdate
        preg_match($match_pattern, 'm/d/yy', $match_arr);
    }
    $retval['date_seperator'] = $match_arr[2];
    // unset all but [dmy]+
    unset($match_arr[0], $match_arr[2], $match_arr[4]);
    $retval['date_order'] = array();
    foreach ($match_arr as $v) {
        // 'm/d/yy' => $retval[date_order] = array ('m', 'd', 'y');
        $retval['date_order'][] = $v[0];
    }
    return $retval;
}
function getNameDiaSemana($dia_semana)
{
    if (isset($dia_semana)) {
        $culture = sfContext::getInstance()->getUser()->getCulture();
        $dateFormatInfo = sfDateTimeFormatInfo::getInstance($culture);
        $dayNames = $dateFormatInfo->getDayNames();
        $value = isset($dayNames[$dia_semana]) ? $dayNames[$dia_semana] : "";
        return $value;
    }
    return null;
}
Example #10
0
 public static function getDateForCulture($date, $culture)
 {
     if (!$date) {
         return 0;
     }
     $dateFormatInfo = @sfDateTimeFormatInfo::getInstance($culture);
     $dateFormat = $dateFormatInfo->getShortDatePattern();
     // We construct the regexp based on date format
     $dateRegexp = preg_replace('/[dmy]+/i', '(\\d+)', $dateFormat);
     // We parse date format to see where things are (m, d, y)
     $a = array('d' => strpos($dateFormat, 'd'), 'm' => strpos($dateFormat, 'M'), 'y' => strpos($dateFormat, 'y'));
     $tmp = array_flip($a);
     ksort($tmp);
     $i = 0;
     $c = array();
     foreach ($tmp as $value) {
         $c[++$i] = $value;
     }
     $datePositions = array_flip($c);
     // We find all elements
     if (preg_match("~{$dateRegexp}~", $date, $matches)) {
         // We get matching timestamp
         return array($matches[$datePositions['d']], $matches[$datePositions['m']], $matches[$datePositions['y']]);
     } else {
         return null;
     }
 }
Example #11
0
 /**
  * Returns the hour, minute from a date formatted with a given culture.
  *
  * @param  string  $time    The formatted date as string
  * @param  string  $culture The culture
  *
  * @return array   An array with the hour and minute
  */
 public function getTimeForCulture($time, $culture = null)
 {
     if (!$time) {
         return 0;
     }
     $culture = null === $culture ? $this->culture : $culture;
     $timeFormatInfo = @sfDateTimeFormatInfo::getInstance($culture);
     $timeFormat = $timeFormatInfo->getShortTimePattern();
     // We construct the regexp based on time format
     $timeRegexp = preg_replace(array('/[hm]+/i', '/a/'), array('(\\d+)', '(\\w+)'), preg_quote($timeFormat));
     // We parse time format to see where things are (h, m)
     $timePositions = array('h' => strpos($timeFormat, 'H') !== false ? strpos($timeFormat, 'H') : strpos($timeFormat, 'h'), 'm' => strpos($timeFormat, 'm'), 'a' => strpos($timeFormat, 'a'));
     asort($timePositions);
     $i = 0;
     // normalize positions to 0, 1, ...
     // positions that don't exist in the pattern remain false
     foreach ($timePositions as $key => $value) {
         if ($value !== false) {
             $timePositions[$key] = ++$i;
         }
     }
     // We find all elements
     if (preg_match("~{$timeRegexp}~", $time, $matches)) {
         // repect am/pm setting if present
         if ($timePositions['a'] !== false) {
             if (strcasecmp($matches[$timePositions['a']], $timeFormatInfo->getAMDesignator()) == 0) {
                 $hour = $matches[$timePositions['h']];
             } else {
                 if (strcasecmp($matches[$timePositions['a']], $timeFormatInfo->getPMDesignator()) == 0) {
                     $hour = $matches[$timePositions['h']] + 12;
                 } else {
                     // am/pm marker is invalid
                     // return null; would be the preferred solution but this might break a lot of code
                     $hour = $matches[$timePositions['h']];
                 }
             }
         } else {
             $hour = $matches[$timePositions['h']];
         }
         // We get matching timestamp
         return array($hour, $matches[$timePositions['m']]);
     } else {
         return null;
     }
 }
Example #12
0
 /**
  * Returns the hour, minute from a date formatted with a given culture.
  *
  * @param  string  $time    The formatted date as string
  * @param  string  $culture The culture
  *
  * @return array   An array with the hour and minute
  */
 public function getTimeForCulture($time, $culture)
 {
     if (!$time) {
         return 0;
     }
     $culture = is_null($culture) ? $this->culture : $culture;
     $timeFormatInfo = @sfDateTimeFormatInfo::getInstance($culture);
     $timeFormat = $timeFormatInfo->getShortTimePattern();
     // We construct the regexp based on time format
     $timeRegexp = preg_replace(array('/[^hm:]+/i', '/[hm]+/i'), array('', '(\\d+)'), $timeFormat);
     // We parse time format to see where things are (h, m)
     $a = array('h' => strpos($timeFormat, 'H') !== false ? strpos($timeFormat, 'H') : strpos($timeFormat, 'h'), 'm' => strpos($timeFormat, 'm'));
     $tmp = array_flip($a);
     ksort($tmp);
     $i = 0;
     $c = array();
     foreach ($tmp as $value) {
         $c[++$i] = $value;
     }
     $timePositions = array_flip($c);
     // We find all elements
     if (preg_match("~{$timeRegexp}~", $time, $matches)) {
         // We get matching timestamp
         return array($matches[$timePositions['h']], $matches[$timePositions['m']]);
     } else {
         return null;
     }
 }
 protected function getJavascriptConfig()
 {
     $requestContext = $this->serviceContainer->getParameter('request.context');
     return $this->dispatcher->filter(new sfEvent($this, 'layout.filter_config'), array_merge($this->getService('response')->getJavascriptConfig(), array('relative_url_root' => $requestContext['relative_url_root'], 'dm_core_asset_root' => $requestContext['relative_url_root'] . '/' . sfConfig::get('dm_core_asset') . '/', 'script_name' => sfConfig::get('sf_no_script_name') ? trim($requestContext['relative_url_root'], '/') . '/' : $requestContext['script_name'] . '/', 'debug' => sfConfig::get('sf_debug') ? true : false, 'culture' => $this->serviceContainer->getParameter('user.culture'), 'dateFormat' => $this->getJQueryDateFormat(sfDateTimeFormatInfo::getInstance($this->serviceContainer->getParameter('user.culture'))->getShortDatePattern()), 'module' => $this->serviceContainer->getParameter('controller.module'), 'action' => $this->serviceContainer->getParameter('controller.action'), 'authenticated' => $this->getService('user')->isAuthenticated())))->getReturnValue();
 }
Example #14
0
function zz_input_date_tag($name, $value, $options = array())
{
    $options = _parse_attributes($options);
    $context = sfContext::getInstance();
    if (isset($options['culture'])) {
        $culture = $options['culture'];
        unset($options['culture']);
    } else {
        $culture = $context->getUser()->getCulture();
    }
    // rich control?
    $rich = false;
    if (isset($options['rich'])) {
        $rich = $options['rich'];
        unset($options['rich']);
    }
    if (!$rich) {
        throw new sfException('input_date_tag (rich=off) is not yet implemented');
    }
    $date_pattern = 'p';
    if (isset($options['date_pattern'])) {
        $date_pattern = $options['date_pattern'];
        unset($options['date_pattern']);
    }
    // parse date
    if ($value === null || $value === '') {
        $value = '';
    } else {
        $dateFormat = new sfDateFormat($culture);
        $value = $dateFormat->format($value, $date_pattern);
    }
    // register our javascripts and stylesheets
    $langFile = '/sf/js/calendar/lang/calendar-' . strtolower(substr($culture, 0, 2));
    $jss = array('/sf/js/calendar/calendar', is_readable(sfConfig::get('sf_symfony_data_dir') . '/web/' . $langFile . '.js') ? $langFile : '/sf/js/calendar/lang/calendar-en', '/sf/js/calendar/calendar-setup');
    foreach ($jss as $js) {
        $context->getResponse()->addJavascript($js);
    }
    $context->getResponse()->addStylesheet('/sf/js/calendar/skins/aqua/theme');
    // date format
    $dateFormatInfo = sfDateTimeFormatInfo::getInstance($culture);
    $date_format = strtolower($dateFormatInfo->getShortDatePattern());
    // calendar date format
    $calendar_date_format = $date_format;
    $calendar_date_format = strtr($calendar_date_format, array('M' => 'm', 'y' => 'Y'));
    $calendar_date_format = preg_replace('/([mdy])+/i', '%\\1', $calendar_date_format);
    $js = '
    document.getElementById("trigger_' . $name . '").disabled = false;
    Calendar.setup({
      inputField : "' . get_id_from_name($name) . '",
      ifFormat : "' . $calendar_date_format . '",
      button : "trigger_' . $name . '"
    });
  ';
    // construct html
    if (!isset($options['size'])) {
        $options['size'] = 9;
    }
    $html = input_tag($name, $value, $options);
    // calendar button
    $calendar_button = '...';
    $calendar_button_type = 'txt';
    if (isset($options['calendar_button_img'])) {
        $calendar_button = $options['calendar_button_img'];
        $calendar_button_type = 'img';
        unset($options['calendar_button_img']);
    } else {
        if (isset($options['calendar_button_txt'])) {
            $calendar_button = $options['calendar_button_txt'];
            $calendar_button_type = 'txt';
            unset($options['calendar_button_txt']);
        }
    }
    if ($calendar_button_type == 'img') {
        $html .= image_tag($calendar_button, array('id' => 'trigger_' . $name, 'style' => 'cursor: pointer; vertical-align: middle'));
    } else {
        $html .= content_tag('button', $calendar_button, array('type' => 'button', 'disabled' => 'disabled', 'onclick' => 'return false', 'id' => 'trigger_' . $name));
    }
    if (isset($options['with_format'])) {
        $html .= '(' . $date_format . ')';
        unset($options['with_format']);
    }
    // add javascript
    $html .= content_tag('script', $js, array('type' => 'text/javascript'));
    return $html;
}