本文整理汇总了PHP中TimeExpressionParser::setLanguage方法的典型用法代码示例。如果您正苦于以下问题:PHP TimeExpressionParser::setLanguage方法的具体用法?PHP TimeExpressionParser::setLanguage怎么用?PHP TimeExpressionParser::setLanguage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeExpressionParser
的用法示例。
在下文中一共展示了TimeExpressionParser::setLanguage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testIncompleteRanges
public function testIncompleteRanges()
{
$o_tep = new TimeExpressionParser();
$o_tep->setLanguage('en_US');
$va_date = getDate();
$vb_res = $o_tep->parse('August 20 - 27 2011');
$this->assertEquals($vb_res, true);
$va_parse = $o_tep->getHistoricTimestamps();
$this->assertEquals($va_parse['start'], '2011.082000000000');
$this->assertEquals($va_parse['end'], '2011.082723595900');
$vb_res = $o_tep->parse('August 20 - 27');
$this->assertEquals($vb_res, true);
$va_parse = $o_tep->getHistoricTimestamps();
$this->assertEquals($va_parse['start'], $va_date['year'] . '.082000000000');
$this->assertEquals($va_parse['end'], $va_date['year'] . '.082723595900');
$vb_res = $o_tep->parse('March - June 1850');
$this->assertEquals($vb_res, true);
$va_parse = $o_tep->getHistoricTimestamps();
$this->assertEquals($va_parse['start'], '1850.030100000000');
$this->assertEquals($va_parse['end'], '1850.063023595900');
}
示例2: _generateSortableValue
/**
* Returns version of label 'display' field value suitable for sorting
* The sortable value is the same as the display value except when the display value
* starts with a definite article ('the' in English) or indefinite article ('a' or 'an' in English)
* in the locale of the label, in which case the article is moved to the end of the sortable value.
*
* What constitutes an article is defined in the TimeExpressionParser localization files. So if the
* locale of the label doesn't correspond to an existing TimeExpressionParser localization, then
* the users' current locale setting is used.
*/
private function _generateSortableValue()
{
if ($vs_sort_field = $this->getProperty('LABEL_SORT_FIELD')) {
$vs_display_field = $this->getProperty('LABEL_DISPLAY_FIELD');
$o_tep = new TimeExpressionParser();
$t_locale = new ca_locales();
$o_tep->setLanguage($t_locale->localeIDToCode($this->get('locale_id')));
$o_lang_settings = $o_tep->getLanguageSettings();
$vs_display_value = trim(preg_replace('![^\\p{L}0-9 ]+!u', ' ', $this->get($vs_display_field)));
$va_definite_articles = $o_lang_settings->get('definiteArticles');
$va_indefinite_articles = $o_lang_settings->get('indefiniteArticles');
foreach (array($o_lang_settings->get('definiteArticles'), $o_lang_settings->get('indefiniteArticles')) as $va_articles) {
if (is_array($va_articles)) {
foreach ($va_articles as $vs_article) {
if (preg_match('!^(' . $vs_article . ')[ ]+!i', $vs_display_value, $va_matches)) {
$vs_display_value = trim(str_replace($va_matches[1], '', $vs_display_value) . ', ' . $va_matches[1]);
break 2;
}
}
}
}
$this->set($vs_sort_field, $vs_display_value);
}
}
示例3: refine
/**
*
*/
public function refine(&$pa_destination_data, $pa_group, $pa_item, $pa_source_data, $pa_options = null)
{
$o_log = isset($pa_options['log']) && is_object($pa_options['log']) ? $pa_options['log'] : null;
$pm_value = $pa_source_data[$pa_item['source']];
// not actually used
$va_item_dest = explode(".", $pa_item['destination']);
$vs_item_terminal = array_pop($va_item_dest);
$vs_group_terminal = array_pop($va_item_dest);
$o_tep = new TimeExpressionParser();
$o_tep->setLanguage('en_US');
switch ($vs_mode = $pa_item['settings']['dateJoiner_mode']) {
default:
case 'range':
$vs_date_expression = $pa_item['settings']['dateJoiner_expression'];
$vs_date_start = $pa_item['settings']['dateJoiner_start'];
$vs_date_end = $pa_item['settings']['dateJoiner_end'];
if ($vs_date_expression && ($vs_exp = BaseRefinery::parsePlaceholder($vs_date_expression, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')))) {
if ($o_tep->parse($vs_exp)) {
return $o_tep->getText();
} else {
if ($o_log) {
$o_log->logWarn(_t('[dateJoinerRefinery] Could not parse date expression %1 assembled from range', $vs_exp));
}
}
}
$va_date = array();
if ($vs_date_start = BaseRefinery::parsePlaceholder($vs_date_start, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' '))) {
if (!($vs_skip_start_exp = $pa_item['settings']['dateJoiner_skipStartIfExpression']) || !ExpressionParser::evaluate($vs_skip_start_exp, array_merge($pa_source_data, array('start' => $vs_date_start, 'end' => $vs_date_end, 'expression' => $ps_expression)))) {
$va_date[] = $vs_date_start;
} elseif ($vs_skip_start_replacement = $pa_item['settings']['dateJoiner_skipStartIfExpressionReplacementValue']) {
$va_date[] = $vs_skip_start_replacement;
}
}
if ($vs_date_end = BaseRefinery::parsePlaceholder($vs_date_end, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' '))) {
if (!($vs_skip_end_exp = $pa_item['settings']['dateJoiner_skipEndIfExpression']) || !ExpressionParser::evaluate($vs_skip_end_exp, array_merge($pa_source_data, array('start' => $vs_date_start, 'end' => $vs_date_end, 'expression' => $ps_expression)))) {
$va_date[] = $vs_date_end;
} elseif ($vs_skip_end_replacement = $pa_item['settings']['dateJoiner_skipEndIfExpressionReplacementValue']) {
$va_date[] = $vs_skip_end_replacement;
}
}
foreach ($va_date as $vn_i => $vs_date) {
$va_date[$vn_i] = preg_replace("![^\\d]+\$!", "", $vs_date);
}
$vs_date_expression = join(" - ", $va_date);
if ($vs_date_expression && ($vs_exp = BaseRefinery::parsePlaceholder($vs_date_expression, $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')))) {
if ($o_tep->parse($vs_exp)) {
return $o_tep->getText();
} else {
if ($o_log) {
$o_log->logWarn(_t('[dateJoinerRefinery] Could not parse date expression %1 assembled from range', $vs_exp));
}
}
}
break;
case 'multiColumnDate':
$va_month_list = $o_tep->getMonthList();
$va_date = array();
if ($vs_date_month = trim(BaseRefinery::parsePlaceholder($pa_item['settings']['dateJoiner_month'], $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')))) {
if (($vn_m = array_search($vs_date_month, $va_month_list)) !== false) {
$vs_date_month = $vn_m + 1;
}
$va_date[] = $vs_date_month;
}
if ($vs_date_day = trim(BaseRefinery::parsePlaceholder($pa_item['settings']['dateJoiner_day'], $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')))) {
$va_date[] = $vs_date_day;
}
if ($vs_date_year = trim(BaseRefinery::parsePlaceholder($pa_item['settings']['dateJoiner_year'], $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')))) {
$va_date[] = $vs_date_year;
}
if (sizeof($va_date)) {
// TODO: this is assuming US-style dates for now
if ($o_tep->parse(join("/", $va_date))) {
return $o_tep->getText();
} else {
if ($o_log) {
$o_log->logWarn(_t('[dateJoinerRefinery] Could not parse date expression %1 assembled from multiColumnDate', join("/", $va_date)));
}
}
}
break;
case 'multiColumnRange':
$va_dates = array();
$va_month_list = $o_tep->getMonthList();
// Process start date
$va_date = array();
if ($vs_date_month = trim(BaseRefinery::parsePlaceholder($pa_item['settings']['dateJoiner_startMonth'], $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')))) {
if (($vn_m = array_search($vs_date_month, $va_month_list)) !== false) {
$vs_date_month = $vn_m + 1;
}
$va_date[] = $vs_date_month;
}
if ($vs_date_day = trim(BaseRefinery::parsePlaceholder($pa_item['settings']['dateJoiner_startDay'], $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')))) {
$va_date[] = $vs_date_day;
}
if ($vs_date_year = trim(BaseRefinery::parsePlaceholder($pa_item['settings']['dateJoiner_startYear'], $pa_source_data, $pa_item, $vn_c, array('reader' => caGetOption('reader', $pa_options, null), 'returnAsString' => true, 'delimiter' => ' ')))) {
$va_date[] = $vs_date_year;
}
//.........这里部分代码省略.........