对日期进行格式化

@param timestamp $value 变量值
@param array $rule array('format' => 'timestamp', 'min' => '最小值', 'max' => '最大值')
@return timesatmp/string 格式化后的变量
425758
public function parse($value, $rule) {
        $rs = $value;

        $ruleFormat = !empty($rule['format']) ? strtolower($rule['format']) : '';
        if ($ruleFormat == 'timestamp') {
            $rs = strtotime($value);
            if ($rs <= 0) {
            	$rs = 0;
            }

            if (isset($rule['min']) && !is_numeric($rule['min'])) {
                $rule['min'] = strtotime($rule['min']);
            }
            if (isset($rule['max']) && !is_numeric($rule['max'])) {
                $rule['max'] = strtotime($rule['max']);
            }

            $rs = $this->filterByRange($rs, $rule);
        }

        return $rs;
    }
1076537
public static function getFormatValue($value) {

        if ( $value instanceof \MongoId ) return $value;

        $opt = substr($value, 0, 2);
        //1.包含双字符操作符的
        if ( isset(self::$operator[$opt]) ) {
            //获取真正的value
            $_value = substr($value, 2);
            return array(self::$operator[$opt] => $_value);
        }

        //2.包含单字符操作符的
        if ( isset(self::$operator[$value[0]]) ) {
            //获取真正的value
            $_value = substr($value, 1);
            return array(self::$operator[$value[0]] => $_value);
        }

        return $value;
    }
1345483
protected static function parseDateValue($value, $format, $timeZone)
    {
        $date = DateTime::createFromFormat($format, $value, new DateTimeZone($timeZone));
        $errors = DateTime::getLastErrors();
        if ($date === false || $errors['error_count'] || $errors['warning_count']) {
            return false;
        } else {
            // if no time was provided in the format string set time to 0 to get a simple date timestamp
            if (strpbrk($format, 'UHhGgis') === false) {
                $date->setTime(0, 0, 0);
            }
            return $date;
        }
    }
1002389
protected function elt($value, $rule, $data)
    {
        $val = $this->getDataValue($data, $rule);

        return !is_null($val) && $value <= $val;
    }
1207407
protected function formatEnumValue($value, $rule) {
        if (!in_array($value, $rule['range'])) {
            $message = isset($rule['message'])
                ? \PhalApi\T($rule['message'])
                : \PhalApi\T('{name} should be in {range}, but now {name} = {value}', 
                    array('name' => $rule['name'], 'range' => implode('/', $rule['range']), 'value' => $value));
            throw new BadRequestException($message);
        }
    }
102091
protected function timestamp_to_date_array($value) {
        $calendartype = \core_calendar\type_factory::get_calendar_instance();
        $currentdate = $calendartype->timestamp_to_date_array($value, $this->_options['timezone']);
        return array(
            'minute' => $currentdate['minutes'],
            'hour' => $currentdate['hours'],
            'day' => $currentdate['mday'],
            'month' => $currentdate['mon'],
            'year' => $currentdate['year']);
    }
578825
public function setTimestamp(\AgentSIB\Diadoc\Api\Proto\Timestamp $value = null)
    {
        $this->Timestamp = $value;
    }
562311
public static function checkCompareValue($rule, $value)
    {
        if(isset($rule[0]) && '!' === $rule[0])
        {
            // 不等
            return $value !== $rule;
        }
        else
        {
            // 相等
            return $value === $rule;
        }
    }
526020
public static function format($format, $value)
    {
        switch ($format) {
            case 'date-time':
                return self::formatDateTime($value);
            case 'date-time-http':
                return self::formatDateTimeHttp($value);
            case 'date':
                return self::formatDate($value);
            case 'time':
                return self::formatTime($value);
            case 'timestamp':
                return self::formatTimestamp($value);
            case 'boolean-string':
                return self::formatBooleanAsString($value);
            default:
                return $value;
        }
    }
1355491
public static function datetime($value, $format = 'Y-m-d H:i:s')
    {
        if (empty($value)) {
            return null;    
        }
        
        $datetime = new \DateTime($value);

        return $datetime->format($format);
    }
875192
public function apply(Rule $rule, $value)
    {
        //trim() only operates in default mode
        //if no second argument is passed, it
        //cannot be passed as null
        if ($rule->charlist === null) {
            return trim($value);
        }

        return trim($value, $rule->charlist);
    }
630799
public function decorateTime($value, $echoToday = false, $dateFormat = null)
    {
        if (empty($value) || $value == '0000-00-00 00:00:00') {
            $value = '';
        } else {
            $value = Mage::getModel('core/date')->date($dateFormat, $value);
            $replace = array(
                Mage::getModel('core/date')->date('Y-m-d ', time()) => $echoToday ? Mage::helper('aoe_scheduler')->__('Today') . ', ' : '', // today
                Mage::getModel('core/date')->date('Y-m-d ', strtotime('+1 day')) => Mage::helper('aoe_scheduler')->__('Tomorrow') . ', ',
                Mage::getModel('core/date')->date('Y-m-d ', strtotime('-1 day')) => Mage::helper('aoe_scheduler')->__('Yesterday') . ', ',
            );
            $value = str_replace(array_keys($replace), array_values($replace), $value);
        }
        return $value;
    }
1237701
static function date($value, &$error, $args){
        $format = isset($args[0])? $args[0] : false;
        if (is_scalar($value)){
            if(is_int($value)){
                $timestamp = $value;
            }else{
                $timestamp = strtotime(strval($value));
            }
            if($timestamp !== false){
                if($format){
                    $value = date($format, $timestamp);
                }
                return $value;
            }
        }
        $error = new Error('Некорректная дата');
        return $value;
    }
927064
public function createDateTime($value)
    {
        $date = null;

        if(is_string($value)) {
            $date = new \DateTime($value);
        }

        if(is_int($value)) {
            $date = new \DateTime();
            $date->setTimestamp($value);
        }

        return $date;
    }
220476
protected function parseTime($value)
    {
        // Skip empty values
        if (empty($value) && !is_numeric($value)) {
            return null;
        }

        // Determine value to parse
        if (is_array($value)) {
            $source = $value; // parse array
        } elseif (is_numeric($value)) {
            $source = $value; // parse timestamp
        } else {
            // Convert using strtotime
            $source = strtotime($value);
        }
        if ($value === false) {
            return false;
        }

        // Format as iso8601
        $formatter = $this->getFormatter();
        $formatter->setPattern($this->getISOFormat());
        return $formatter->format($source);
    }
733751
private static function _parseDateTimeString($value)
    {
        $result = @preg_match('/^\d\d\d\d-\d?\d-\d?\d \d\d:\d\d:\d\d$/', $value);
        if ($result !== 1)
            return null;
        $timestamp = strtotime($value);
        if ($timestamp === false)
            return null;

        return $timestamp;
    }
821473
public function is($value, $rule, $data = [])
    {
        $rule = preg_replace_callback('/_([a-zA-Z])/', function ($match) {
            return strtoupper($match[1]);
        }, $rule);

        switch (lcfirst($rule)) {
            case 'require':
                // 必须
                $result = !empty($value) || '0' == $value;
                break;
            case 'accepted':
                // 接受
                $result = in_array($value, ['1', 'on', 'yes']);
                break;
            case 'date':
                // 是否是一个有效日期
                $result = false !== strtotime($value);
                break;
            case 'activeUrl':
                // 是否为有效的网址
                $result = checkdnsrr($value);
                break;
            case 'boolean':
            case 'bool':
                // 是否为布尔值
                $result = in_array($value, [true, false, 0, 1, '0', '1'], true);
                break;
            case 'number':
                $result = is_numeric($value);
                break;
            case 'array':
                // 是否为数组
                $result = is_array($value);
                break;
            case 'file':
                $result = $value instanceof SplFileObject;
                break;
            case 'image':
                $result = $value instanceof SplFileObject && in_array($this->getImageType($value->getRealPath()), [1, 2, 3, 6]);
                break;
            default:
                if (isset(self::$type[$rule])) {
                    // 注册的验证规则
                    $result = call_user_func_array(self::$type[$rule], [$value]);
                } elseif (isset($this->filter[$rule])) {
                    // Filter_var验证规则
                    $result = $this->filter($value, $this->filter[$rule]);
                } else {
                    // 正则验证
                    $result = $this->regex($value, $rule);
                }
        }

        return $result;
    }