/usr/share/php/Horde/Date/Parser/Locale/Pt.php is in php-horde-date-parser 2.0.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | <?php
/**
*/
class Horde_Date_Parser_Locale_Pt extends Horde_Date_Parser_Locale_Base
{
public $definitions = array();
public $args = array();
public $now;
public function __construct($args)
{
$this->args = $args;
}
/**
* Parses a string containing a natural language date or time. If the
* parser can find a date or time, either a Horde_Date or Horde_Date_Span
* will be returned (depending on the value of <tt>:return</tt>). If no
* date or time can be found, +nil+ will be returned.
*
* Options are:
*
* [<tt>:context</tt>]
* <tt>:past</tt> or <tt>:future</tt> (defaults to <tt>:future</tt>)
*
* If your string represents a birthday, you can set <tt>:context</tt>
* to <tt>:past</tt> and if an ambiguous string is given, it will
* assume it is in the past. Specify <tt>:future</tt> or omit to set a
* future context.
*
* [<tt>:now</tt>]
* Time (defaults to time())
*
* By setting <tt>:now</tt> to a Horde_Date, all computations will be
* based off of that time instead of time().
*
* [<tt>:return</tt>]
* 'result', 'span', or 'date' (defaults to 'date')
*
* By default, the parser will guess a single point in time for the
* given date or time. If you'd rather have the entire time span
* returned, set <tt>:return</tt> to 'span' and a Horde_Date_Span will
* be returned. If you want the entire result, including tokens (for
* retrieving the text that was or was not tagged, for example), set
* <tt>:return</tt> to 'result' and you will get a result object.
*
* [<tt>:ambiguousTimeRange</tt>]
* Integer or <tt>:none</tt> (defaults to <tt>6</tt> (6am-6pm))
*
* If an Integer is given, ambiguous times (like 5:00) will be assumed
* to be within the range of that time in the AM to that time in the
* PM. For example, if you set it to <tt>7</tt>, then the parser will
* look for the time between 7am and 7pm. In the case of 5:00, it would
* assume that means 5:00pm. If <tt>:none</tt> is given, no assumption
* will be made, and the first matching instance of that time will be
* used.
*/
public function parse($text, $specifiedOptions = array())
{
// get options and set defaults if necessary
$defaultOptions = array(
'context' => 'future',
'now' => new Horde_Date(time()),
'return' => 'date',
'ambiguousTimeRange' => 6,
);
$options = array_merge($defaultOptions, $this->args, $specifiedOptions);
// ensure the specified options are valid
foreach (array_keys($specifiedOptions) as $key) {
if (!isset($defaultOptions[$key])) {
throw new InvalidArgumentException("$key is not a valid option key");
}
}
if (!in_array($options['context'], array('past', 'future', 'none'))) {
throw new InvalidArgumentException("Invalid value " . $options['context'] . " for 'context' specified. Valid values are 'past', 'future', and 'none'");
}
// store now for later =)
$this->now = $options['now'];
$text = $this->normalize_special_characters($text);
// put the text into a normal format to ease scanning
$text = $this->preNormalize($text);
// get base tokens for each word
$tokens = $this->preTokenize($text);
// scan the tokens with each token scanner
foreach (array('Repeater') as $tokenizer) {
$tokenizer = $this->componentFactory($tokenizer);
$tokens = $tokenizer->scan($tokens, $options);
}
foreach (array('Grabber', 'Pointer', 'Scalar', 'Ordinal', 'Separator', 'Timezone') as $tokenizer) {
$tokenizer = $this->componentFactory($tokenizer);
$tokens = $tokenizer->scan($tokens);
}
// strip any non-tagged tokens
$taggedTokens = array_values(array_filter($tokens, create_function('$t', 'return $t->tagged();')));
// Remove tokens we know we don't want - for example, if the first
// token is a separator, drop it.
$taggedTokens = $this->postTokenize($taggedTokens);
// do the heavy lifting
$span = $this->tokensToSpan($taggedTokens, $options);
// generate the result and return it, the span, or a guessed time
// within the span
$result = new Horde_Date_Parser_Result($span, $tokens);
switch ($options['return']) {
case 'result':
return $result;
case 'span':
return $result->span;
case 'date':
return $result->guess();
}
}
/**
* Replaces special characters with non-special equivalents.
*
* Source: http://pt2.php.net/manual/en/function.chr.php#93291
*/
public function normalize_special_characters($str)
{
// Quotes cleanup
$str = str_replace(
array(
chr(ord("`")),
chr(ord("´")),
chr(ord("„")),
chr(ord("`")),
chr(ord("´")),
chr(ord("“")),
chr(ord("”")),
chr(ord("´")),
),
array(
"'",
"'",
",",
"'",
"'",
"\"",
"\"",
"'",
),
$str
);
$unwanted_array = array(
'Š'=>'S', 'š'=>'s', 'Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A',
'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C',
'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I',
'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O',
'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U',
'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a',
'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c',
'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i',
'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o',
'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u',
'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y'
);
$str = strtr($str, $unwanted_array);
// Bullets, dashes, and trademarks
$str = str_replace(
array(
chr(149), # bullet •
chr(150), # en dash
chr(151), # em dash
chr(153), # trademark
chr(169), # copyright mark
chr(174), # registration mark
),
array(
'•',
'–',
'—',
'™',
'©',
'®',
),
$str
);
return $str;
}
/**
* Clean up the specified input text by stripping unwanted characters,
* converting idioms to their canonical form, converting number words to
* numbers (three => 3), and converting ordinal words to numeric ordinals
* (third => 3rd)
*/
public function preNormalize($text)
{
// fix email parser
$text = preg_replace('/\b([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})\b/', '', $text);
$text = strtolower($text);
$text = $this->numericizeNumbers($text);
// fix url parser
$text = preg_replace('/(?:(?:https?|ftp):\/\/)/', '', $text);
// composed sentences
$text = preg_replace(
array(
'/\bsegunda[ \-]feira\b/',
'/\bterca[ \-]feira\b/',
'/\bquarta[ \-]feira\b/',
'/\bquinta[ \-]feira\b/',
'/\bsexta[ \-]feira\b/',
'/[\'"\.]/',
'/([\/\-\,\@])/',
'/\bhoje\b/',
'/\bamanh[aã]\b/',
'/\bontem\b/',
'/\bfim de semana\b/',
'/\bmeio\s+dia\b/',
'/\bmeia\s+noite\b/',
'/\b(antes|anterior)\b/',
'/\b(agora|j[aá])\b/',
'/\b[uú]ltim[oa]\b/',
'/\b(?:de|na|durante\s+a|logo(?:\s[aà]|de))\s+(manh[aã]|madrugada)\b/',
'/\b(?:de|[àa]|durante\s+a|logo(?:\s[aà]|de))\s+tarde\b/',
'/\b((?:de|[àa]|durante\s+a|logo(?:\s[aà]))\s+noite|(?:ao)\s+anoitecer)\b/',
),
array(
'segunda',
'terca',
'quarta',
'quinta',
'sexta',
'',
' $1 ',
'this day',
'next day',
'last day',
'fds',
'12:00',
'24:00',
'past',
'this second',
'last',
'morning',
'afternoon',
'this night',
),
$text
);
$text = preg_replace_callback(
'/\b([0-1]?[0-9]|2[0-3])(:|,|.)?([0-5][0-9])?\s?(horas?)\b/',
function($matches) {
$minute = ($matches[3] != '')
? str_pad($matches[3], 2 , '0', STR_PAD_LEFT)
: '00';
$hour = $matches[1];
return $hour . ':' . $minute . ' oclock';
},
$text
);
$text = preg_replace(
array(
'/\b(horas?|h|hrs?)\b/',
'/\b(depois|ap[oó]s)\b/',
'/\bdia\b/',
),
array(
' oclock',
'future',
'', // broke parser: redundant, ignore and read from number day
),
$text
);
// $text = $this->numericizeNumbers($text);
return $text;
}
/**
* Convert ordinal words to numeric ordinals (third => 3rd)
*/
public function numericizeOrdinals($text)
{
/*
$text = preg_replace('/^d[eé]cim[oa]\s+primeir[oa]$/', '11º', $text);
$text = preg_replace('/^d[eé]cim[oa]\s+segund[oa]$/', '12º', $text);
$text = preg_replace('/^d[eé]cim[oa]\s+terceir[oa]$/', '13º', $text);
$text = preg_replace('/^d[eé]cim[oa]\s+quart[oa]$/', '14º', $text);
$text = preg_replace('/^d[eé]cim[oa]\s+quint[oa]$/', '15º', $text);
$text = preg_replace('/^d[eé]cim[oa]\s+sext[oa]$/', '16º', $text);
$text = preg_replace('/^d[eé]cim[oa]\s+s[eé]tim[oa]$/', '17º', $text);
$text = preg_replace('/^d[eé]cim[oa]\s+oit[aá]v[oa]$/', '18º', $text);
$text = preg_replace('/^d[eé]cim[oa]\s+^non[oa]$/', '19º', $text);
$text = preg_replace('/^primeir[oa]$/', '1º', $text);
$text = preg_replace('/^segund[oa]$/', '2º', $text);
$text = preg_replace('/^terceir[oa]$/', '3º', $text);
$text = preg_replace('/^quart[oa]$/', '4º', $text);
$text = preg_replace('/^quint[oa]$/', '5º', $text);
$text = preg_replace('/^sext[oa]$/', '6º', $text);
$text = preg_replace('/^s[eé]tim[oa]$/', '7º', $text);
$text = preg_replace('/^oit[aá]v[oa]$/', '8º', $text);
$text = preg_replace('/^non[oa]$/', '9º', $text);
$text = preg_replace('/^d[eé]cim[oa]$/', '10º', $text);
// and so one....
*/
return $text;
}
public function initDefinitions()
{
if ($this->definitions) { return; }
$this->definitions = array(
'time' => array(
// new Horde_Date_Parser_Handler(array(':repeater_time', ':repeater_day_portion?'), null),
new Horde_Date_Parser_Handler(array(':separator_at?', ':repeater_time', ':repeater_day_portion?'), null),
new Horde_Date_Parser_Handler(array(':separator_at?', ':time', ':repeater_time'), null), // ás 10 horas
/*
new Horde_Date_Parser_Handler(array(':repeater_day_portion?', ':repeater_time' ), null),
new Horde_Date_Parser_Handler(array(':separator_at?', ':repeater_time' ), null),
new Horde_Date_Parser_Handler(array(':repeater_time', ':separator_at?', ':repeater_day_portion?'), null),
*/
),
'date' => array(
new Horde_Date_Parser_Handler(array(':repeater_day_name', ':repeater_month_name', ':scalar_day', ':repeater_time', ':timezone', ':scalar_year'), 'handle_rdn_rmn_sd_t_tz_sy'),
new Horde_Date_Parser_Handler(array(':repeater_month_name', ':scalar_day', ':scalar_year'), 'handle_rmn_sd_sy'),
new Horde_Date_Parser_Handler(array(':repeater_month_name', ':scalar_day', ':scalar_year', ':separator_at?', 'time?'), 'handle_rmn_sd_sy'),
new Horde_Date_Parser_Handler(array(':repeater_month_name', ':scalar_day', ':separator_at?', 'time?'), 'handle_rmn_sd'),
new Horde_Date_Parser_Handler(array(':repeater_month_name', ':ordinal_day', ':separator_at?', 'time?'), 'handle_rmn_od'),
new Horde_Date_Parser_Handler(array(':repeater_month_name', ':scalar_year'), 'handle_rmn_sy'),
new Horde_Date_Parser_Handler(array(':scalar_day', ':repeater_month_name', ':scalar_year', ':separator_at?', 'time?'), 'handle_sd_rmn_sy'),
new Horde_Date_Parser_Handler(array(':scalar_month', ':separator_slash_or_dash', ':scalar_day', ':separator_slash_or_dash', ':scalar_year', ':separator_at?', 'time?'), 'handle_sm_sd_sy'),
new Horde_Date_Parser_Handler(array(':scalar_day', ':separator_slash_or_dash', ':scalar_month', ':separator_slash_or_dash', ':scalar_year', ':separator_at?', 'time?'), 'handle_sd_sm_sy'),
new Horde_Date_Parser_Handler(array(':scalar_year', ':separator_slash_or_dash', ':scalar_month', ':separator_slash_or_dash', ':scalar_day', ':separator_at?', 'time?'), 'handle_sy_sm_sd'),
new Horde_Date_Parser_Handler(array(':scalar_month', ':separator_slash_or_dash', ':scalar_year'), 'handle_sm_sy'),
new Horde_Date_Parser_Handler(array(':scalar_day', ':separator_at?', ':repeater_month_name', ':separator_at?', ':scalar_year', ':separator_at?', 'time?'), 'handle_sd_rmn_sy'),
/*
new Horde_Date_Parser_Handler(array(':scalar_day', ':separator_at?', ':repeater_month_name', ':separator_at?', 'time?'), 'handle_sd_rmn'),
new Horde_Date_Parser_Handler(array(':ordinal_day', ':separator_at?', ':repeater_month_name', ':separator_at?', 'time?'), 'handle_od_rmn'),
new Horde_Date_Parser_Handler(array(':repeater_day_name', ':separator_at?', ':time?'), 'handle_rdn'),
new Horde_Date_Parser_Handler(array(':scalar_day', ':separator_at?', ':scalar_month', ':separator_at?', ':scalar_year?', 'time?'), 'handle_sd_sm_sy'),
new Horde_Date_Parser_Handler(array(':scalar_day', ':separator_at?', ':repeater_month_name', ':separator_at?', ':scalar_year', ':separator_at?', 'time?'), 'handle_sd_rmn_sy'),
*/
new Horde_Date_Parser_Handler(array(':scalar_day', ':separator_slash_or_dash', ':scalar_month', ':separator_slash_or_dash', ':scalar_year', ':separator_at?', 'time?'), 'handle_sd_sm_sy'),
new Horde_Date_Parser_Handler(array(':scalar_year', ':separator_slash_or_dash', ':scalar_month', ':separator_slash_or_dash', ':scalar_day', ':separator_at?', 'time?'), 'handle_sy_sm_sd'),
new Horde_Date_Parser_Handler(array(':scalar_month', ':separator_slash_or_dash', ':scalar_year'), 'handle_sm_sy'),
),
// tonight at 7pm
'anchor' => array(
new Horde_Date_Parser_Handler(array(':grabber?', ':repeater', ':separator_at?', ':repeater?', ':repeater?'), 'handle_r'),
new Horde_Date_Parser_Handler(array(':grabber?', ':repeater', ':repeater', ':separator_at?', ':repeater?', ':repeater?'), 'handle_r'),
new Horde_Date_Parser_Handler(array(':repeater', ':grabber', ':repeater'), 'handle_r_g_r'),
),
// 3 weeks from now, in 2 months
'arrow' => array(
new Horde_Date_Parser_Handler(array(':scalar', ':repeater', ':pointer'), 'handle_s_r_p'),
new Horde_Date_Parser_Handler(array(':pointer', ':scalar', ':repeater'), 'handle_p_s_r'),
new Horde_Date_Parser_Handler(array(':scalar', ':repeater', ':pointer', 'anchor'), 'handle_s_r_p_a'),
),
// 3rd week in march
'narrow' => array(
new Horde_Date_Parser_Handler(array(':ordinal', ':repeater', ':separator_in', ':repeater'), 'handle_o_r_s_r'),
new Horde_Date_Parser_Handler(array(':ordinal', ':repeater', ':grabber', ':repeater'), 'handle_o_r_g_r'),
),
);
}
public function handle_rdn($tokens, $options)
{
try {
return $this->dayOrTime(
new Horde_Date(time()), array($tokens[0]), $options
);
} catch (Exception $e) {
return null;
}
}
// JPC
public function handle_sd_rmn($tokens, $options)
{
return $this->handle_m_d(
$tokens[1]->getTag('repeater_month_name'),
$tokens[0]->getTag('scalar_day'),
array_slice($tokens, 2),
$options
);
}
public function handle_od_rmn($tokens, $options)
{
return $this->handle_m_d(
$tokens[1]->getTag('repeater_month_name'),
$tokens[0]->getTag('ordinal_day'),
array_slice($tokens, 2),
$options
);
}
}
|