Tools\Utility\Time::period PHP Method

period() public static method

.. to)
public static period ( string $searchString, array $options = [] ) : array
$searchString string Search string to parse
$options array - separator (defaults to space [ ]) - format (defaults to Y-m-d H:i:s)
return array period [0=>min, 1=>max]
    public static function period($searchString, array $options = [])
    {
        if (strpos($searchString, ' ') !== false) {
            $filters = explode(' ', $searchString);
            $filters = [array_shift($filters), array_pop($filters)];
        } else {
            $filters = [$searchString, $searchString];
        }
        $min = $filters[0];
        $max = $filters[1];
        $min = static::parseLocalizedDate($min);
        $max = static::parseLocalizedDate($max, null, 'end');
        return [$min, $max];
    }

Usage Example

コード例 #1
0
ファイル: TimeTest.php プロジェクト: alescx/cakephp-tools
 /**
  * TimeTest::testPeriod()
  *
  * @return void
  */
 public function testPeriod()
 {
     //$this->out($this->_header(__FUNCTION__), true);
     $values = [[__d('tools', 'Today'), [date(FORMAT_DB_DATETIME, mktime(0, 0, 0, date('m'), date('d'), date('Y'))), date(FORMAT_DB_DATETIME, mktime(23, 59, 59, date('m'), date('d'), date('Y')))]], ['2010', ['2010-01-01 00:00:00', '2010-12-31 23:59:59']], ['2011-02', ['2011-02-01 00:00:00', '2011-02-28 23:59:59']], ['2012-02', ['2012-02-01 00:00:00', '2012-02-29 23:59:59']], ['2010-02-23', ['2010-02-23 00:00:00', '2010-02-23 23:59:59']], ['2010-02-23 bis 2010-02-26', ['2010-02-23 00:00:00', '2010-02-26 23:59:59']], ['23.02.2011', ['2011-02-23 00:00:00', '2011-02-23 23:59:59']], ['23.2.2010 bis 26.2.2011', ['2010-02-23 00:00:00', '2011-02-26 23:59:59']]];
     foreach ($values as $v) {
         $ret = $this->Time->period($v[0]);
         //pr($ret);
         $this->assertEquals($v[1], $ret);
     }
 }