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


PHP CDateTimeParser::parse方法代码示例

本文整理汇总了PHP中CDateTimeParser::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP CDateTimeParser::parse方法的具体用法?PHP CDateTimeParser::parse怎么用?PHP CDateTimeParser::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CDateTimeParser的用法示例。


在下文中一共展示了CDateTimeParser::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parseDate

 public static function parseDate($date)
 {
     if (($t = CDateTimeParser::parse($date, 'dd/MM/yyyy')) || ($t = CDateTimeParser::parse($date, 'yyyy-MM-dd'))) {
         return date("Y-m-d", $t);
     }
     return null;
 }
开发者ID:jankichaudhari,项目名称:yii-site,代码行数:7,代码来源:Date.php

示例2: validateAttribute

 protected function validateAttribute($object, $attribute)
 {
     $message = Yii::t('yii', '{attribute} must be greater than "{compareValue}".');
     $compare = $this->compare;
     /*if (empty($object->attributes[$compare]) && empty($object->attributes[$attribute])) return;*/
     if ($object->attributes[$compare] == null && $object->attributes[$attribute] == null) {
         return;
     }
     Yii::log($object->attributes[$compare] . " " . $object->attributes[$attribute]);
     if (!isset($object->attributes[$attribute])) {
         $object->addError($attribute, 'An ' . $object->getAttributeLabel($attribute) . ' is required.');
     }
     if ($compare == null) {
         throw new CException('Compare value is required.');
     }
     if (!isset($object->attributes[$compare])) {
         $object->addError($compare, 'A ' . $object->getAttributeLabel($compare) . ' is required.');
     }
     if (!$object->hasErrors($attribute)) {
         $value = $object->attributes[$attribute];
         $compareValue = $object->attributes[$compare];
         $pattern = $this->pattern;
         if (CDateTimeParser::parse($value, $pattern) < CDateTimeParser::parse($compareValue, $pattern)) {
             $params = array('{attribute}' => $object->getAttributeLabel($attribute), '{compareValue}' => $object->getAttributeLabel($compare));
             $object->addError($attribute, strtr($message, $params));
         }
     }
 }
开发者ID:aakbar24,项目名称:CollegeCorner_Ver_2.0,代码行数:28,代码来源:CompareStartEndDates.php

示例3: testParseDefaults

 function testParseDefaults()
 {
     $this->assertEquals('31-12-2011 23:59:59', date('d-m-Y H:i:s', CDateTimeParser::parse('2011-12-31', 'yyyy-MM-dd', array('hour' => 23, 'minute' => 59, 'second' => 59))));
     // test matching with wildcards, this example is mssql timestamp
     $this->assertEquals('2011-02-10 23:43:04', date('Y-m-d H:i:s', CDateTimeParser::parse('2011-02-10 23:43:04.973', 'yyyy-MM-dd hh:mm:ss.???')));
     $this->assertEquals('2011-01-10 23:43:04', date('Y-m-d H:i:s', CDateTimeParser::parse('2011-01-10 23:43:04.973', 'yyyy?MM?dd?hh?mm?ss????')));
 }
开发者ID:nirleka,项目名称:yii,代码行数:7,代码来源:CDateTimeParserTest.php

示例4: actionAddWorker

 function actionAddWorker()
 {
     $model = new Worker();
     $user = new User();
     $u_transaction = $user->dbConnection->beginTransaction();
     $this->performAjaxValidation($user);
     if (isset($_POST['Worker'])) {
         if (isset($_POST['User'])) {
             $user->login = $_POST['User']['login'];
             $user->password = $_POST['User']['password'];
             $user->role = 'worker';
             if ($user->save()) {
                 $model->attributes = $_POST['Worker'];
                 $model->user_id = $user->id;
                 $timestamp = CDateTimeParser::parse($model->birthdate, 'dd-MM-yyyy');
                 $model->birthdate = date('Y-m-d', $timestamp);
                 if ($model->save()) {
                     $u_transaction->commit();
                     $this->redirect(array('view', 'id' => $model->user_id));
                 } else {
                     $u_transaction->rollback();
                     //откатываем данные по юзеру, в случае если данные по работнику не сохранились
                     throw new CHttpException(901, 'Ошибка сохранения данных работника.');
                 }
             } else {
                 throw new CHttpException(902, "Ошибка сохранения данных авторизации");
             }
         } else {
             throw new CHttpException(903, 'Ошибка передачи данных авторизации.');
         }
     } else {
         $this->render('add_worker', array('model' => $model, 'user' => $user));
     }
 }
开发者ID:vnilov,项目名称:delivery,代码行数:34,代码来源:MainController.php

示例5: validateAttribute

 /**
  * Validates the attribute of the object.
  * If there is any error, the error message is added to the object.
  * @param CModel $object the object being validated
  * @param string $attribute the attribute being validated
  */
 protected function validateAttribute($object, $attribute)
 {
     $value = $object->{$attribute};
     if ($this->allowEmpty && $this->isEmpty($value)) {
         return;
     }
     $valid = false;
     // reason of array checking is explained here: https://github.com/yiisoft/yii/issues/1955
     if (!is_array($value)) {
         $formats = is_string($this->format) ? array($this->format) : $this->format;
         foreach ($formats as $format) {
             $timestamp = CDateTimeParser::parse($value, $format, array('month' => 1, 'day' => 1, 'hour' => 0, 'minute' => 0, 'second' => 0));
             if ($timestamp !== false) {
                 $valid = true;
                 if ($this->timestampAttribute !== null) {
                     $object->{$this->timestampAttribute} = $timestamp;
                 }
                 break;
             }
         }
     }
     if (!$valid) {
         $message = $this->message !== null ? $this->message : Yii::t('yii', 'The format of {attribute} is invalid.');
         $this->addError($object, $attribute, $message);
     }
 }
开发者ID:ubertheme,项目名称:module-ubdatamigration,代码行数:32,代码来源:CDateValidator.php

示例6: actionCronDaily

 public function actionCronDaily($type)
 {
     set_time_limit(0);
     $logmodel = HoleCronLog::model()->findByAttributes(array('type' => $type), 'time_finish >= ' . CDateTimeParser::parse(date('Y-m-d'), 'yyyy-MM-dd'));
     if (!$logmodel) {
         $logmodel = new HoleCronLog();
         if ($type == "achtung-notifications") {
             $logmodel->type = $type;
             $logmodel->time_finish = time();
             $logmodel->save();
             //отмечаем ямы как просроченные
             $holes = Holes::model()->findAll(array('condition' => 't.STATE in ("inprogress", "achtung") AND t.DATE_SENT > 0'));
             foreach ($holes as $hole) {
                 $WAIT_DAYS = 38 - ceil((time() - $hole->DATE_SENT) / 86400);
                 if ($WAIT_DAYS < 0 && $hole->STATE == 'inprogress') {
                     $hole->STATE = 'achtung';
                     $hole->update();
                 } elseif ($hole->STATE == 'achtung' && $WAIT_DAYS > 0) {
                     $hole->STATE = 'inprogress';
                     $hole->update();
                 }
             }
             //echo count($holes);
             //Находим пользователей с просроченными запросами
             $users = 1;
             $limit = 200;
             $ofset = 0;
             while ($users) {
                 $users = UserGroupsUser::model()->findAll(array('select' => '*, t.id as notUseAfrefind', 'condition' => 'relProfile.send_achtung_notifications=1 AND t.email != ""', 'with' => array('relProfile', 'requests' => array('with' => array('answer', 'hole' => array('with' => array('type', 'pictures_fresh'))), 'condition' => 'requests.date_sent < ' . (time() - 60 * 60 * 24 * 28) . ' AND requests.type="gibdd" AND (requests.notification_sended=0 OR requests.notification_sended < ' . (time() - 60 * 60 * 24 * 30) . ' ) AND hole.STATE NOT IN ("fixed", "prosecutor") AND answer.request_id IS NULL'), 'relUserGroupsGroup'), 'limit' => $limit, 'offset' => $ofset));
                 foreach ($users as $user) {
                     $holes = array();
                     $i = 0;
                     foreach ($user->requests as $request) {
                         $WAIT_DAYS = 38 - ceil((time() - $request->date_sent) / 86400);
                         if ($WAIT_DAYS < 0) {
                             $holes[$i] = $request->hole;
                             $holes[$i]->PAST_DAYS = abs($WAIT_DAYS);
                             $i++;
                             $request->notification_sended = time();
                             $request->update();
                         }
                     }
                     if ($holes) {
                         $headers = "MIME-Version: 1.0\r\nFrom: \"Rosyama\" <" . Yii::app()->params['adminEmail'] . ">\r\nReply-To: " . Yii::app()->params['adminEmail'] . "\r\nContent-Type: text/html; charset=utf-8";
                         Yii::app()->request->baseUrl = Yii::app()->request->hostInfo;
                         $mailbody = $this->renderPartial('/ugmail/achtung_notification', array('user' => $user, 'holes' => $holes), true);
                         //echo $mailbody; die();
                         //$user->email
                         echo 'Напоминание на ' . count($holes) . 'ям, отправлено пользователю ' . $user->username . '<br />';
                         mail($user->email, "=?utf-8?B?" . base64_encode('Истекло время ожидания ответа от ГИБДД') . "?=", $mailbody, $headers);
                     }
                     unset($holes);
                 }
                 $ofset += $limit;
                 //if ($ofset > 2000) break;
             }
             $this->render('/site/index');
         }
     }
 }
开发者ID:ASDAFF,项目名称:RosYama.2,代码行数:60,代码来源:HolesController.php

示例7: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Person();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Person'])) {
         $model->attributes = $_POST['Person'];
         $model->job = 0;
         $model->birthday = CDateTimeParser::parse($model->birthday, 'dd/MM/yyyy');
         $model->avatar = CUploadedFile::getInstance($model, 'avatar');
         if ($model->avatar != null) {
             $avatar_name = 'image_' . $model->id . '_' . time() . '.' . $model->avatar->getExtensionName();
             $model->avatar->saveAs(Yii::getPathOfAlias('webroot') . Person::M_IMAGES . $avatar_name);
             $image = Yii::app()->image->load(Yii::getPathOfAlias('webroot') . Person::M_IMAGES . $avatar_name);
             if (128 < $image->__get('width')) {
                 $image->resize(128, 128, Image::HEIGHT);
             }
             $image->save(Yii::getPathOfAlias('webroot') . Person::M_THUMBNAIL . $avatar_name);
             // or $image->save('images/small.jpg');
             $model->avatar = $avatar_name;
         } else {
             $model->avatar = Person::M_NOIMAGE;
         }
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
开发者ID:google-code-backups,项目名称:yii-vn,代码行数:33,代码来源:ArtistController.php

示例8: beforeValidate

 public function beforeValidate()
 {
     parent::beforeValidate();
     if ($this->birthday && $this->birthday != '0000-00-00') {
         $this->birthday = date('Y-m-d', CDateTimeParser::parse($this->birthday, 'dd.MM.yyyy'));
     }
     return true;
 }
开发者ID:snipesn,项目名称:UkrYama-2,代码行数:8,代码来源:Profile.php

示例9: init

 public function init()
 {
     $yiidatetimesec = Yii::app()->locale->getDateFormat('yiidatetimesec');
     $phpdatetime = Yii::app()->locale->getDateFormat('phpdatetimes');
     $this->from_date = date($phpdatetime, CDateTimeParser::parse('01/01/' . date('Y') . ' 00:00:00', $yiidatetimesec));
     $this->to_date = date($phpdatetime);
     return parent::init();
 }
开发者ID:hkhateb,项目名称:linet3,代码行数:8,代码来源:FormProfloss.php

示例10: formatDateTime

 public static function formatDateTime($dateTime, $format = 'default')
 {
     $dateFormat = param('dateFormat', 'd.m.Y H:i:s');
     if ($format == 'default') {
         return date($dateFormat, strtotime($dateTime));
     } else {
         return Yii::app()->dateFormatter->format(Yii::app()->locale->getDateFormat('long'), CDateTimeParser::parse($dateTime, 'yyyy-MM-dd hh:mm:ss'));
     }
 }
开发者ID:alexjkitty,项目名称:estate,代码行数:9,代码来源:HDate.php

示例11: transaction

 public function transaction($in, $out, $model)
 {
     $due_date = DocchequesEav::model()->findByPk(array("doc_id" => $model->doc_id, "line" => $model->line, 'attribute' => 'cheque_date'));
     if ($due_date == NULL) {
         throw new Exception("NO due date was found for transaction", 401);
     }
     $valuedate = date("Y-m-d H:m:s", CDateTimeParser::parse($due_date->value, Yii::app()->locale->getDateFormat('yiishort')));
     $in->valuedate = $valuedate;
     $out->valuedate = $valuedate;
 }
开发者ID:hkhateb,项目名称:linet3,代码行数:10,代码来源:Check.php

示例12: inbox_date

function inbox_date($time_str)
{
    $tstamp = strtotime($time_str);
    if (date('z', time()) <= date('z', $tstamp)) {
        $date_str = Yii::app()->dateFormatter->format('h:mm a', CDateTimeParser::parse($tstamp, 'yyyy-MM-dd'), 'medium', null);
    } else {
        $date_str = Yii::app()->dateFormatter->format('MMM d', CDateTimeParser::parse($tstamp, 'yyyy-MM-dd'), 'medium', null);
    }
    return $date_str;
}
开发者ID:mafiu,项目名称:listapp,代码行数:10,代码来源:helpers.php

示例13: sanitizeValue

 /**
  * Given a value, attempt to convert the value to a db datetime format based on the format provided.
  * If the value does not convert properly, meaning the value is not really in the format specified, then a
  * InvalidValueToSanitizeException will be thrown.
  * @param mixed $value
  * @return sanitized value
  * @throws InvalidValueToSanitizeException
  */
 public function sanitizeValue($value)
 {
     if ($value == null) {
         return $value;
     }
     $timeStamp = CDateTimeParser::parse($value, $this->mappingRuleData['format']);
     if ($timeStamp === false || !is_int($timeStamp)) {
         throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Invalid datetime format.'));
     }
     return DateTimeUtil::convertTimestampToDbFormatDateTime($timeStamp);
 }
开发者ID:youprofit,项目名称:Zurmo,代码行数:19,代码来源:DateTimeSanitizerUtil.php

示例14: actionUserinputSave

 public function actionUserinputSave()
 {
     if (isset($_POST['item_id']) && $_POST['item_id'] > 0 && isset($_POST['DtTest'])) {
         $item_id = (int) $_POST['item_id'];
         $model = DtTest::model()->findByPk($item_id);
         $model->c_date = Yii::app()->dateFormatter->formatDateTime(CDateTimeParser::parse($_POST['DtTest']['c_date'], Yii::app()->locale->getDateFormat('small')), 'database', false);
         $model->c_time = $_POST['c_time_hour'] . ':' . $_POST['c_time_min'] . ':00';
         $model->c_datetime = Yii::app()->lc->mergeDatetime(array('date' => $_POST['DtTest']['c_datetime'], 'hour' => $_POST['c_datetime_hour'], 'min' => $_POST['c_datetime_min']), 'database', 'small');
         $model->save();
     }
 }
开发者ID:TianJinRong,项目名称:yiiplayground,代码行数:11,代码来源:DatetimeController.php

示例15: validateAttribute

 protected function validateAttribute($object, $attribute)
 {
     $message = Yii::t('yii', '{attribute} must be greater than "{compareValue}".');
     $compare = $this->compare;
     /*if (empty($object->attributes[$compare]) && empty($object->attributes[$attribute])) return;*/
     if ($object->attributes[$compare] == null && $object->attributes[$attribute] == null) {
         return;
     }
     if (!isset($object->attributes[$attribute])) {
         $object->addError($attribute, 'An ' . $object->getAttributeLabel($attribute) . ' is required.');
     }
     if ($compare == null) {
         throw new CException('Compare value is required.');
     }
     if (!isset($object->attributes[$compare])) {
         $object->addError($compare, 'A ' . $object->getAttributeLabel($compare) . ' is required.');
     }
     if (!$object->hasErrors(null)) {
         $value = $object->attributes[$attribute];
         $compareValue = $object->attributes[$compare];
         $pattern = $this->pattern;
         $startDate = $this->startDate;
         $endDate = $this->endDate;
         $checkTime = true;
         if ($this->checkSameDate) {
             if ($startDate == null) {
                 throw new CException('"startDate" is required.');
             }
             if ($endDate == null) {
                 throw new CException('"endDate" is required.');
             }
             if (!isset($object->attributes[$startDate])) {
                 $object->addError($startDate, 'Time requires a ' . $object->getAttributeLabel($startDate) . '.');
             }
             if (!isset($object->attributes[$endDate])) {
                 $object->addError($endDate, 'Time requires an ' . $object->getAttributeLabel($endDate) . '.');
             }
             if (!$object->hasErrors($attribute)) {
                 $startDateValue = $object->attributes[$startDate];
                 $endDateValue = $object->attributes[$endDate];
                 $datePattern = $this->datePattern;
                 $checkTime = CDateTimeParser::parse($startDateValue, $datePattern) == CDateTimeParser::parse($endDateValue, $datePattern);
                 if ($checkTime) {
                     if (CDateTimeParser::parse($value, $pattern) <= CDateTimeParser::parse($compareValue, $pattern)) {
                         $params = array('{attribute}' => $object->getAttributeLabel($attribute), '{compareValue}' => $object->getAttributeLabel($compare));
                         $object->addError($attribute, strtr($message, $params));
                     }
                 }
             }
         }
     }
 }
开发者ID:aakbar24,项目名称:CollegeCorner_Ver_2.0,代码行数:52,代码来源:CompareStartEndTimes.php


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