本文整理匯總了PHP中Zend_Locale_Format::getCorrectableDate方法的典型用法代碼示例。如果您正苦於以下問題:PHP Zend_Locale_Format::getCorrectableDate方法的具體用法?PHP Zend_Locale_Format::getCorrectableDate怎麽用?PHP Zend_Locale_Format::getCorrectableDate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Zend_Locale_Format
的用法示例。
在下文中一共展示了Zend_Locale_Format::getCorrectableDate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: testgetDate
/**
* test getDate
* expected array
*/
public function testgetDate()
{
try {
$value = Zend_Locale_Format::getDate('no content');
$this->fail("no date expected");
} catch (Zend_Locale_Exception $e) {
// success
}
$this->assertEquals(is_array(Zend_Locale_Format::getDate('10.10.06')), true, "array expected");
$this->assertEquals(count(Zend_Locale_Format::getDate('10.10.06', 'dd.MM.yy')), 4, "array with 4 tags expected");
$value = Zend_Locale_Format::getDate('10.11.06', 'dd.MM.yy');
$this->assertEquals($value['day'], 10, 'Day 10 expected');
$this->assertEquals($value['month'], 11, 'Month 11 expected');
$this->assertEquals($value['year'], 06, 'Year 06 expected');
$value = Zend_Locale_Format::getDate('10.11.2006', 'dd.MM.yy');
$this->assertSame($value['day'], 10, 'Day 10 expected');
$this->assertSame($value['month'], 11, 'Month 11 expected');
$this->assertSame($value['year'], 2006, 'Year 2006 expected');
try {
$value = Zend_Locale_Format::getDate('2006.13.01', 'dd.MM.yy');
$this->fail("no date expected");
} catch (Zend_Locale_Exception $e) {
$this->assertRegexp('/unable.to.parse/i', $e->getMessage());
// success
}
$value = Zend_Locale_Format::getCorrectableDate('2006.13.01', 'dd.MM.yy');
$this->assertEquals($value['day'], 13, 'Day 13 expected');
$this->assertEquals($value['month'], 1, 'Month 1 expected');
$this->assertEquals($value['year'], 2006, 'Year 2006 expected');
try {
$value = Zend_Locale_Format::getDate('2006.01.13', 'dd.MM.yy');
$this->fail("no date expected");
} catch (Zend_Locale_Exception $e) {
$this->assertRegexp('/unable.to.parse/i', $e->getMessage());
// success
}
$value = Zend_Locale_Format::getCorrectableDate('2006.01.13', 'dd.MM.yy');
$this->assertEquals($value['day'], 13, 'Day 13 expected');
$this->assertEquals($value['month'], 1, 'Month 1 expected');
$this->assertEquals($value['year'], 2006, 'Year 2006 expected');
$value = Zend_Locale_Format::getDate('101106', 'ddMMyy');
$this->assertEquals($value['day'], 10, 'Day 10 expected');
$this->assertEquals($value['month'], 11, 'Month 11 expected');
$this->assertEquals($value['year'], 6, 'Year 6 expected');
$value = Zend_Locale_Format::getDate('10112006', 'ddMMyyyy');
$this->assertEquals($value['day'], 10, 'Day 10 expected');
$this->assertEquals($value['month'], 11, 'Month 11 expected');
$this->assertEquals($value['year'], 2006, 'Year 2006 expected');
$value = Zend_Locale_Format::getDate('10 Nov 2006', 'dd.MMM.yy', 'de_AT');
$this->assertEquals($value['day'], 10, 'Day 10 expected');
$this->assertEquals($value['month'], 11, 'Month 11 expected');
$this->assertEquals($value['year'], 2006, 'Year 2006 expected');
$value = Zend_Locale_Format::getDate('10 November 2006', 'dd.MMM.yy', 'de_AT');
$this->assertEquals($value['day'], 10, 'Day 10 expected');
$this->assertEquals($value['month'], 11, 'Month 11 expected');
$this->assertEquals($value['year'], 2006, 'Year 2006 expected');
try {
$value = Zend_Locale_Format::getDate('November 10 2006', 'dd.MMM.yy', 'de_AT');
$this->fail("no date expected");
} catch (Zend_Locale_Exception $e) {
$this->assertRegexp('/unable.to.parse/i', $e->getMessage());
// success
}
$value = Zend_Locale_Format::getCorrectableDate('November 10 2006', 'dd.MMM.yy', 'de_AT');
$this->assertEquals($value['day'], 10, 'Day 10 expected');
$this->assertEquals($value['month'], 11, 'Month 11 expected');
$this->assertEquals($value['year'], 2006, 'Year 2006 expected');
try {
$value = Zend_Locale_Format::getDate('Nov 10 2006', 'dd.MMM.yy', 'de_AT');
$this->fail("no date expected");
} catch (Zend_Locale_Exception $e) {
$this->assertRegexp('/unable.to.parse/i', $e->getMessage());
// success
}
$value = Zend_Locale_Format::getCorrectableDate('Nov 10 2006', 'dd.MMM.yy', 'de_AT');
$this->assertEquals($value['day'], 10, 'Day 10 expected');
$this->assertEquals($value['month'], 11, 'Month 11 expected');
$this->assertEquals($value['year'], 2006, 'Year 2006 expected');
try {
$value = Zend_Locale_Format::getDate('2006 10 Nov', 'dd.MMM.yy', 'de_AT');
$this->fail("no date expected");
} catch (Zend_Locale_Exception $e) {
$this->assertRegexp('/unable.to.parse/i', $e->getMessage());
// success
}
$value = Zend_Locale_Format::getCorrectableDate('2006 10 Nov', 'dd.MMM.yy', 'de_AT');
$this->assertEquals($value['day'], 10, 'Day 10 expected');
$this->assertEquals($value['month'], 11, 'Month 11 expected');
$this->assertEquals($value['year'], 2006, 'Year 2006 expected');
// @todo failed test, auto completion doesnt work for this case
// $value = Zend_Locale_Format::getDate('2006 Nov 10','dd.MMM.yy', 'de_AT');
// $this->assertEquals($value['day'], 10, 'Day 10 expected');
// $this->assertEquals($value['month'], 11, 'Month 11 expected');
// $this->assertEquals($value['year'], 2006, 'Year 2006 expected');
$value = Zend_Locale_Format::getDate('10.11.06', 'yy.dd.MM');
$this->assertEquals($value['day'], 11, 'Day 11 expected');
//.........這裏部分代碼省略.........
示例2: _date
/**
* Returns the calculated date
*
* @param string $calc Calculation to make
* @param string|integer|Zend_Date $date Date to calculate with, if null the actual date is taken
* @param string $format Dateformat for parsing
* @param string|Zend_Locale $locale Locale for parsing input
* @return integer|Zend_Date new date
* @throws Zend_Date_Exception
*/
private function _date($calc, $date, $format, $locale)
{
if (is_null($date)) {
throw new Zend_Date_Exception('parameter $date must be set, null is not allowed');
}
if ($locale === null) {
$locale = $this->getLocale();
}
if ($date instanceof Zend_Date) {
// extract date from object
$date = $date->get(Zend_Date::DATE_MEDIUM, $locale);
} else {
$parsed = Zend_Locale_Format::getCorrectableDate($date, $format, $locale);
$date = new Zend_Date(0, Zend_Date::TIMESTAMP, $locale);
$date->set($parsed['year'], Zend_Date::YEAR);
$date->set($parsed['month'], Zend_Date::MONTH);
$date->set($parsed['day'], Zend_Date::DAY);
$date = $date->get(Zend_Date::DATE_MEDIUM, $locale);
}
$return = $this->_calcdetail($calc, $date, Zend_Date::DATE_MEDIUM, $locale);
if ($calc != 'cmp') {
return $this;
}
return $return;
}