Exemplo n.º 1
0
/**
 * Stub implementation for the intl_error_name function of the intl extension
 *
 * @return String will be the same as the name of the error code constant
 *
 * @see    Symfony\Component\Locale\Stub\StubIntl::getErrorName
 */
function intl_error_name($errorCode)
{
    return StubIntl::getErrorName($errorCode);
}
 /**
  * @dataProvider parseProvider
  */
 public function testParseStub($pattern, $value, $expected, $errorCode = 0, $errorMessage = 'U_ZERO_ERROR')
 {
     $formatter = $this->createStubFormatter($pattern);
     $this->assertSame($expected, $formatter->parse($value));
     $this->assertSame($errorMessage, StubIntl::getErrorMessage());
     $this->assertSame($errorCode, StubIntl::getErrorCode());
     $this->assertSame($errorCode != 0, StubIntl::isFailure(StubIntl::getErrorCode()));
 }
 /**
  * Parse string to a timestamp value
  *
  * @param  string   $value      String to convert to a time value
  * @param  int      $position   Position at which to start the parsing in $value (zero-based).
  *                              If no error occurs before $value is consumed, $parse_pos will
  *                              contain -1 otherwise it will contain the position at which parsing
  *                              ended. If $parse_pos > strlen($value), the parse fails immediately.
  *
  * @return string               Parsed value as a timestamp
  *
  * @see    http://www.php.net/manual/en/intldateformatter.parse.php
  *
  * @throws MethodArgumentNotImplementedException  When $position different than null, behavior not implemented
  */
 public function parse($value, &$position = null)
 {
     // We don't calculate the position when parsing the value
     if (null !== $position) {
         throw new MethodArgumentNotImplementedException(__METHOD__, 'position');
     }
     StubIntl::setErrorCode(StubIntl::U_ZERO_ERROR);
     $dateTime = $this->createDateTime(0);
     $transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId());
     return $transformer->parse($dateTime, $value);
 }
Exemplo n.º 4
0
 /**
  * @dataProvider codeProvider
  */
 public function testGetErrorNameWithIntl($code, $name)
 {
     $this->skipIfIntlExtensionIsNotLoaded();
     $this->assertSame(intl_error_name($code), StubIntl::getErrorName($code));
 }
 /**
  * Set the error to the default U_ZERO_ERROR
  */
 protected function resetError()
 {
     StubIntl::setError(StubIntl::U_ZERO_ERROR);
     $this->errorCode = StubIntl::getErrorCode();
     $this->errorMessage = StubIntl::getErrorMessage();
 }
Exemplo n.º 6
0
 /**
  * Calculates the Unix timestamp based on the matched values by the reverse matching regular
  * expression of parse()
  *
  * @param DateTime $dateTime The DateTime object to be used to calculate the timestamp
  * @param array    $options  An array with the matched values to be used to calculate the timestamp
  *
  * @return Boolean|int        The calculated timestamp or false if matched date is invalid
  */
 protected function calculateUnixTimestamp(\DateTime $dateTime, array $options)
 {
     $options = $this->getDefaultValueForOptions($options);
     $year = $options['year'];
     $month = $options['month'];
     $day = $options['day'];
     $hour = $options['hour'];
     $hourInstance = $options['hourInstance'];
     $minute = $options['minute'];
     $second = $options['second'];
     $marker = $options['marker'];
     $timezone = $options['timezone'];
     // If month is false, return immediately (intl behavior)
     if (false === $month) {
         StubIntl::setError(StubIntl::U_PARSE_ERROR, 'Date parsing failed');
         return false;
     }
     // Normalize hour
     if ($hourInstance instanceof HourTransformer) {
         $hour = $hourInstance->normalizeHour($hour, $marker);
     }
     // Set the timezone if different from the default one
     if (null !== $timezone && $timezone !== $this->timezone) {
         $dateTime->setTimezone(new \DateTimeZone($timezone));
     }
     // Normalize yy year
     preg_match_all($this->regExp, $this->pattern, $matches);
     if (in_array('yy', $matches[0])) {
         $dateTime->setTimestamp(time());
         $year = $year > $dateTime->format('y') + 20 ? 1900 + $year : 2000 + $year;
     }
     $dateTime->setDate($year, $month, $day);
     $dateTime->setTime($hour, $minute, $second);
     return $dateTime->getTimestamp();
 }
 /**
  * @dataProvider parseProvider
  */
 public function testParseStub($value, $expected, $message = '')
 {
     $formatter = $this->getStubFormatterWithDecimalStyle();
     $parsedValue = $formatter->parse($value, StubNumberFormatter::TYPE_DOUBLE);
     $this->assertSame($expected, $parsedValue, $message);
     if ($expected === false) {
         $errorCode = StubIntl::U_PARSE_ERROR;
         $errorMessage = 'Number parsing failed: U_PARSE_ERROR';
     } else {
         $errorCode = StubIntl::U_ZERO_ERROR;
         $errorMessage = 'U_ZERO_ERROR';
     }
     $this->assertSame($errorMessage, StubIntl::getErrorMessage());
     $this->assertSame($errorCode, StubIntl::getErrorCode());
     $this->assertSame($errorCode !== 0, StubIntl::isFailure(StubIntl::getErrorCode()));
     $this->assertSame($errorMessage, $formatter->getErrorMessage());
     $this->assertSame($errorCode, $formatter->getErrorCode());
     $this->assertSame($errorCode !== 0, StubIntl::isFailure($formatter->getErrorCode()));
 }
 /**
  * Parse string to a timestamp value
  *
  * @param string $value    String to convert to a time value
  * @param int    $position Position at which to start the parsing in $value (zero-based).
  *                              If no error occurs before $value is consumed, $parse_pos will
  *                              contain -1 otherwise it will contain the position at which parsing
  *                              ended. If $parse_pos > strlen($value), the parse fails immediately.
  *
  * @return string               Parsed value as a timestamp
  *
  * @see    http://www.php.net/manual/en/intldateformatter.parse.php
  *
  * @throws MethodArgumentNotImplementedException  When $position different than null, behavior not implemented
  */
 public function parse($value, &$position = null)
 {
     // We don't calculate the position when parsing the value
     if (null !== $position) {
         throw new MethodArgumentNotImplementedException(__METHOD__, 'position');
     }
     $dateTime = $this->createDateTime(0);
     $transformer = new FullTransformer($this->getPattern(), $this->getTimeZoneId());
     $timestamp = $transformer->parse($dateTime, $value);
     // behave like the intl extension. FullTransformer::parse() set the proper error
     $this->errorCode = StubIntl::getErrorCode();
     $this->errorMessage = StubIntl::getErrorMessage();
     return $timestamp;
 }
 /**
  * @dataProvider parseErrorProvider
  */
 public function testParseErrorStub($pattern, $value)
 {
     $errorCode = StubIntl::U_PARSE_ERROR;
     $errorMessage = 'Date parsing failed: U_PARSE_ERROR';
     $formatter = $this->createStubFormatter($pattern);
     $this->assertFalse($formatter->parse($value));
     $this->assertSame($errorMessage, StubIntl::getErrorMessage());
     $this->assertSame($errorCode, StubIntl::getErrorCode());
     $this->assertTrue(StubIntl::isFailure(StubIntl::getErrorCode()));
     $this->assertSame($errorMessage, $formatter->getErrorMessage());
     $this->assertSame($errorCode, $formatter->getErrorCode());
     $this->assertTrue(StubIntl::isFailure($formatter->getErrorCode()));
 }
Exemplo n.º 10
0
 /**
  * Calculates the Unix timestamp based on the matched values by the reverse matching regular
  * expression of parse()
  *
  * @param  DateTime $dateTime The DateTime object to be used to calculate the timestamp
  * @param  array    $options  An array with the matched values to be used to calculate the timestamp
  * @return Boolean|int        The calculated timestamp or false if matched date is invalid
  */
 protected function calculateUnixTimestamp(\DateTime $dateTime, array $options)
 {
     $options = $this->getDefaultValueForOptions($options);
     $year = $options['year'];
     $month = $options['month'];
     $day = $options['day'];
     $hour = $options['hour'];
     $hourInstance = $options['hourInstance'];
     $minute = $options['minute'];
     $second = $options['second'];
     $marker = $options['marker'];
     $timezone = $options['timezone'];
     // If month is false, return immediately (intl behavior)
     if (false === $month) {
         StubIntl::setErrorCode(StubIntl::U_PARSE_ERROR);
         return false;
     }
     // Normalize hour
     if ($hourInstance instanceof HourTransformer) {
         $hour = $hourInstance->normalizeHour($hour, $marker);
     }
     // Set the timezone if different from the default one
     if (null !== $timezone && $timezone !== $this->timezone) {
         $dateTime->setTimezone(new \DateTimeZone($timezone));
     }
     $dateTime->setDate($year, $month, $day);
     $dateTime->setTime($hour, $minute, $second);
     return $dateTime->getTimestamp();
 }
Exemplo n.º 11
0
/**
 * Stub implementation for the intl_get_error_code function of the intl extension
 *
 * @author Bernhard Schussek <*****@*****.**>
 * @return Boolean The error message of the last intl function call or
 *                 "U_ZERO_ERROR" if no error occurred
 * @see    Symfony\Component\Locale\Stub\StubIntl::getErrorMessage
 */
function intl_get_error_message()
{
    return StubIntl::getErrorMessage();
}
Exemplo n.º 12
0
/**
 * Stub implementation for the intl_get_error_code function of the intl extension
 *
 * @author Bernhard Schussek <*****@*****.**>
 * @return Boolean The error message of the last intl function call or
 *                 "U_ZERO_ERROR" if no error occurred
 * @see    Symfony\Component\Locale\Stub\StubIntl::getErrorMessage
 */
function intl_get_error_message()
{
    return \Symfony\Component\Locale\Stub\StubIntl::getErrorMessage();
}