本文整理汇总了PHP中Zend_Locale_Format::getTime方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Locale_Format::getTime方法的具体用法?PHP Zend_Locale_Format::getTime怎么用?PHP Zend_Locale_Format::getTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Locale_Format
的用法示例。
在下文中一共展示了Zend_Locale_Format::getTime方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _time
/**
* Returns the calculated time
*
* @param string $calc Calculation to make
* @param string|integer|array|Zend_Date $time Time to calculate with, if null the actual time is taken
* @param string $format Timeformat for parsing input
* @param string|Zend_Locale $locale Locale for parsing input
* @return integer|Zend_Date new time
* @throws Zend_Date_Exception
*/
private function _time($calc, $time, $format, $locale)
{
if ($time === null) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception('parameter $time must be set, null is not allowed');
}
if ($time instanceof Zend_Date) {
// extract time from object
$time = $time->toString('HH:mm:ss', 'iso');
} else {
if (is_array($time)) {
if (isset($time['hour']) === true or isset($time['minute']) === true or isset($time['second']) === true) {
$parsed = $time;
} else {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception("no hour, minute or second given in array");
}
} else {
if (self::$_options['format_type'] == 'php') {
$format = Zend_Locale_Format::convertPhpToIsoFormat($format);
}
try {
if ($locale === null) {
$locale = $this->getLocale();
}
$parsed = Zend_Locale_Format::getTime($time, array('date_format' => $format, 'locale' => $locale, 'format_type' => 'iso'));
} catch (Zend_Locale_Exception $e) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception($e->getMessage(), 0, $e);
}
}
if (!array_key_exists('hour', $parsed)) {
$parsed['hour'] = 0;
}
if (!array_key_exists('minute', $parsed)) {
$parsed['minute'] = 0;
}
if (!array_key_exists('second', $parsed)) {
$parsed['second'] = 0;
}
$time = str_pad($parsed['hour'], 2, '0', STR_PAD_LEFT) . ":";
$time .= str_pad($parsed['minute'], 2, '0', STR_PAD_LEFT) . ":";
$time .= str_pad($parsed['second'], 2, '0', STR_PAD_LEFT);
}
$return = $this->_calcdetail($calc, $time, self::TIMES, 'de');
if ($calc != 'cmp') {
return $this;
}
return $return;
}
示例2: filter
/**
* Defined by Zend_Filter_Interface
*
* Normalizes the given input
*
* @param string $value Value to normalized
* @return string|array The normalized value
*/
public function filter($value)
{
if (Zend_Locale_Format::isNumber($value, $this->_options)) {
return Zend_Locale_Format::getNumber($value, $this->_options);
} else {
if ($this->_options['date_format'] === null && strpos($value, ':') !== false) {
// Special case, no date format specified, detect time input
return Zend_Locale_Format::getTime($value, $this->_options);
} else {
if (Zend_Locale_Format::checkDateFormat($value, $this->_options)) {
// Detect date or time input
return Zend_Locale_Format::getDate($value, $this->_options);
}
}
}
return $value;
}
示例3: _time
/**
* Returns the calculated time
*
* @param string $calc Calculation to make
* @param string|integer|array|Zend_Date $time Time to calculate with, if null the actual time is taken
* @param string $format Timeformat for parsing input
* @param string|Zend_Locale $locale Locale for parsing input
* @return integer|Zend_Date new time
* @throws Zend_Date_Exception
*/
private function _time($calc, $time, $format, $locale)
{
if (is_null($time)) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception('parameter $time must be set, null is not allowed');
}
if ($locale === null) {
$locale = $this->getLocale();
}
if ($time instanceof Zend_Date) {
// extract time from object
$time = $time->get(self::TIME_MEDIUM, $locale);
} else {
if (is_array($time)) {
if (isset($time['hour']) === true or isset($time['minute']) === true or isset($time['second']) === true) {
$parsed = $time;
} else {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception("no hour, minute or second given in array");
}
} else {
if (self::$_options['format_type'] == 'php') {
$format = Zend_Locale_Format::convertPhpToIsoFormat($format);
}
try {
$parsed = Zend_Locale_Format::getTime($time, array('date_format' => $format, 'locale' => $locale, 'format_type' => 'iso'));
} catch (Zend_Locale_Exception $e) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception($e->getMessage());
}
}
$time = new self(0, self::TIMESTAMP, $locale);
$time->setTimezone('UTC');
$time->set($parsed['hour'], self::HOUR);
$time->set($parsed['minute'], self::MINUTE);
$time->set($parsed['second'], self::SECOND);
$time = $time->get(self::TIME_MEDIUM, $locale);
}
$return = $this->_calcdetail($calc, $time, self::TIME_MEDIUM, $locale);
if ($calc != 'cmp') {
return $this;
}
return $return;
}
示例4: json_encode
$errors['activityID'] = $kga['lang']['errorMessages']['noActivitySelected'];
}
if (!is_numeric($data['projectID'])) {
$errors['projectID'] = $kga['lang']['errorMessages']['noProjectSelected'];
}
if (count($errors) > 0) {
echo json_encode(array('errors' => $errors));
return;
}
$edit_in_day = Zend_Locale_Format::getDate($_REQUEST['start_day'], array('date_format' => 'dd.MM.yyyy'));
$edit_in_time = Zend_Locale_Format::getTime($_REQUEST['start_time'], array('date_format' => 'HH:mm:ss'));
$edit_in = array_merge($edit_in_day, $edit_in_time);
$inDate = new Zend_Date($edit_in);
if ($_REQUEST['end_day'] != '' || $_REQUEST['end_time'] != '') {
$edit_out_day = Zend_Locale_Format::getDate($_REQUEST['end_day'], array('date_format' => 'dd.MM.yyyy'));
$edit_out_time = Zend_Locale_Format::getTime($_REQUEST['end_time'], array('date_format' => 'HH:mm:ss'));
$edit_out = array_merge($edit_out_day, $edit_out_time);
$outDate = new Zend_Date($edit_out);
} else {
$outDate = null;
}
$data['start'] = $inDate->getTimestamp();
if ($outDate != null) {
$data['end'] = $outDate->getTimestamp();
$data['duration'] = $data['end'] - $data['start'];
}
if ($id) {
// TIME RIGHT - NEW OR EDIT ?
if (!timesheetAccessAllowed($data, $action, $errors)) {
echo json_encode(array('errors' => $errors));
break;
示例5: testgetTime
/**
* test getTime
* expected array
*/
public function testgetTime()
{
try {
$value = Zend_Locale_Format::getTime('no content');
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
$this->assertTrue(is_array(Zend_Locale_Format::getTime('13:14:55', array('date_format' => 'HH:mm:ss'))));
$options = array('date_format' => 'h:mm:ss a', 'locale' => 'en');
$this->assertTrue(is_array(Zend_Locale_Format::getTime('11:14:55 am', $options)));
$this->assertTrue(is_array(Zend_Locale_Format::getTime('12:14:55 am', $options)));
$this->assertTrue(is_array(Zend_Locale_Format::getTime('11:14:55 pm', $options)));
$this->assertTrue(is_array(Zend_Locale_Format::getTime('12:14:55 pm', $options)));
try {
$value = Zend_Locale_Format::getTime('13:14:55', array('date_format' => 'nocontent'));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
try {
$value = Zend_Locale_Format::getTime('13:14:55', array('date_format' => 'ZZZZ'));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
try {
$value = Zend_Locale_Format::getTime('13:14:55', array('date_format' => 'HH:mm:ss.x'));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
$this->assertEquals(5, count(Zend_Locale_Format::getTime('13:14:55', array('date_format' => 'HH:mm:ss'))));
$value = Zend_Locale_Format::getTime('13:14:55', array('date_format' => 'HH:mm:ss'));
$this->assertEquals(13, $value['hour'] );
$this->assertEquals(14, $value['minute']);
$this->assertEquals(55, $value['second']);
$value = Zend_Locale_Format::getTime('131455', array('date_format' => 'HH:mm:ss'));
$this->assertEquals(13, $value['hour'] );
$this->assertEquals(14, $value['minute']);
$this->assertEquals(55, $value['second']);
}
示例6: testgetTime
/**
* test getTime
* expected array
*/
public function testgetTime()
{
try {
$value = Zend_Locale_Format::getTime('no content');
$this->fail("no time expected");
} catch (Zend_Locale_Exception $e) {
// success
}
$this->assertEquals(is_array(Zend_Locale_Format::getTime('13:14:55', array('date_format' => 'HH:mm:ss'))), true, "array expected");
$options = array('date_format' => 'h:mm:ss a', 'locale' => 'en');
$this->assertEquals(is_array(Zend_Locale_Format::getTime('11:14:55 am', $options)), true, "array expected");
$this->assertEquals(is_array(Zend_Locale_Format::getTime('12:14:55 am', $options)), true, "array expected");
$this->assertEquals(is_array(Zend_Locale_Format::getTime('11:14:55 pm', $options)), true, "array expected");
$this->assertEquals(is_array(Zend_Locale_Format::getTime('12:14:55 pm', $options)), true, "array expected");
try {
$value = Zend_Locale_Format::getTime('13:14:55', array('date_format' => 'nocontent'));
$this->fail("no time expected");
} catch (Zend_Locale_Exception $e) {
// success
}
try {
$value = Zend_Locale_Format::getTime('13:14:55', array('date_format' => 'ZZZZ'));
$this->fail("no time expected");
} catch (Zend_Locale_Exception $e) {
// success
}
try {
$value = Zend_Locale_Format::getTime('13:14:55', array('date_format' => 'HH:mm:ss.x'));
$this->fail("no time expected");
} catch (Zend_Locale_Exception $e) {
// success
}
$this->assertEquals(count(Zend_Locale_Format::getTime('13:14:55', array('date_format' => 'HH:mm:ss'))), 5, "array with 5 tags expected");
$value = Zend_Locale_Format::getTime('13:14:55', array('date_format' => 'HH:mm:ss'));
$this->assertEquals($value['hour'], 13, 'Hour 13 expected');
$this->assertEquals($value['minute'], 14, 'Minute 14 expected');
$this->assertEquals($value['second'], 55, 'Second 55 expected');
$value = Zend_Locale_Format::getTime('131455', array('date_format' => 'HH:mm:ss'));
$this->assertEquals($value['hour'], 13, 'Hour 13 expected');
$this->assertEquals($value['minute'], 14, 'Minute 14 expected');
$this->assertEquals($value['second'], 55, 'Second 55 expected');
}
示例7: testgetTimeParsing4
/**
* test if getTime parses a time with fixed format
* expected array
*/
public function testgetTimeParsing4()
{
$value = Zend_Locale_Format::getTime('131455', 'HH:mm:ss');
$this->assertEquals($value['hour'], 13, 'Hour 13 expected');
$this->assertEquals($value['minute'], 14, 'Minute 14 expected');
$this->assertEquals($value['second'], 55, 'Second 55 expected');
}
示例8: _time
/**
* Returns the calculated time
*
* @param string $calc Calculation to make
* @param string|integer|Zend_Date $time Time to calculate with, if null the actual time is taken
* @param string $format Timeformat for parsing input
* @param string|Zend_Locale $locale Locale for parsing input
* @return integer|Zend_Date new time
* @throws Zend_Date_Exception
*/
private function _time($calc, $time, $format, $locale)
{
if (is_null($time)) {
throw new Zend_Date_Exception('parameter $time must be set, null is not allowed');
}
if ($locale === null) {
$locale = $this->getLocale();
}
if ($time instanceof Zend_Date) {
// extract time from object
$time = $time->get(Zend_Date::TIME_MEDIUM, $locale);
} else {
$parsed = Zend_Locale_Format::getTime($time, $format, $locale);
$time = new Zend_Date(0, Zend_Date::TIMESTAMP, $locale);
$time->set($parsed['hour'], Zend_Date::HOUR);
$time->set($parsed['minute'], Zend_Date::MINUTE);
$time->set($parsed['second'], Zend_Date::SECOND);
$time = $time->get(Zend_Date::TIME_MEDIUM, $locale);
}
$return = $this->_calcdetail($calc, $time, Zend_Date::TIME_MEDIUM, $locale);
if ($calc != 'cmp') {
return $this;
}
return $return;
}
示例9: _calculate
//.........这里部分代码省略.........
case Zend_Date::TIMEZONE_SECS:
return false;
break;
// date strings
// date strings
case Zend_Date::ISO_8601:
$result = preg_match('/\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\+\\d{4}/', $date, $match);
if (!$result) {
return false;
}
$years = substr($match[0], 0, 4);
$months = substr($match[0], 5, 2);
$days = substr($match[0], 8, 2);
$hours = substr($match[0], 11, 2);
$minutes = substr($match[0], 14, 2);
$seconds = substr($match[0], 17, 2);
return $this->_assign($calc, $this->_Date->mktime($hours, $minutes, $seconds, $months, $days, $years, -1, $gmt), $this->_Date->mktime($hour, $minute, $second, $month, $day, $year, -1, $gmt));
break;
case Zend_Date::RFC_2822:
$result = preg_match('/\\w{3},\\s\\d{2}\\s\\w{3}\\s\\d{4}\\s\\d{2}:\\d{2}:\\d{2}\\s\\+\\d{4}/', $date, $match);
if (!$result) {
return false;
}
$days = substr($match[0], 5, 2);
$months = $this->getDigitFromName(substr($match[0], 8, 3));
$years = substr($match[0], 12, 4);
$hours = substr($match[0], 17, 2);
$minutes = substr($match[0], 20, 2);
$seconds = substr($match[0], 23, 2);
return $this->_assign($calc, $this->_Date->mktime($hours, $minutes, $seconds, $months, $days, $years, -1, $gmt), $this->_Date->mktime($hour, $minute, $second, $month, $day, $year, -1, $gmt));
break;
case Zend_Date::TIMESTAMP:
if (is_numeric($date)) {
return $this->_assign($calc, $date, $this->getTimestamp());
}
return false;
break;
// additional formats
// break intentionally omitted
// additional formats
// break intentionally omitted
case Zend_Date::ERA:
case Zend_Date::ERA_NAME:
return false;
break;
case Zend_Date::DATES:
$parsed = Zend_Locale_Format::getDate($date, 'default', $locale);
return $this->_assign($calc, $this->_Date->mktime(0, 0, 0, $parsed['month'], $parsed['day'], $parsed['year'], -1, $gmt), $this->_Date->mktime(0, 0, 0, $month, $day, $year, -1, $gmt));
break;
case Zend_Date::DATE_FULL:
$parsed = Zend_Locale_Format::getDate($date, 'full', $locale);
return $this->_assign($calc, $this->_Date->mktime(0, 0, 0, $parsed['month'], $parsed['day'], $parsed['year'], -1, $gmt), $this->_Date->mktime(0, 0, 0, $month, $day, $year, -1, $gmt));
break;
case Zend_Date::DATE_LONG:
$parsed = Zend_Locale_Format::getDate($date, 'long', $locale);
return $this->_assign($calc, $this->_Date->mktime(0, 0, 0, $parsed['month'], $parsed['day'], $parsed['year'], -1, $gmt), $this->_Date->mktime(0, 0, 0, $month, $day, $year, -1, $gmt));
break;
case Zend_Date::DATE_MEDIUM:
$parsed = Zend_Locale_Format::getDate($date, 'medium', $locale);
return $this->_assign($calc, $this->_Date->mktime(0, 0, 0, $parsed['month'], $parsed['day'], $parsed['year'], -1, $gmt), $this->_Date->mktime(0, 0, 0, $month, $day, $year, -1, $gmt));
break;
case Zend_Date::DATE_SHORT:
$parsed = Zend_Locale_Format::getDate($date, 'short', $locale);
return $this->_assign($calc, $this->_Date->mktime(0, 0, 0, $parsed['month'], $parsed['day'], $parsed['year'], -1, $gmt), $this->_Date->mktime(0, 0, 0, $month, $day, $year, -1, $gmt));
break;
case Zend_Date::TIMES: