当前位置: 首页>>代码示例>>PHP>>正文


PHP Zend_Locale_Format::getCorrectableDate方法代码示例

本文整理汇总了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');
//.........这里部分代码省略.........
开发者ID:jorgenils,项目名称:zend-framework,代码行数:101,代码来源:FormatTest.php

示例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;
 }
开发者ID:jorgenils,项目名称:zend-framework,代码行数:35,代码来源:Date.php


注:本文中的Zend_Locale_Format::getCorrectableDate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。