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


PHP I18n\Time类代码示例

本文整理汇总了PHP中Cake\I18n\Time的典型用法代码示例。如果您正苦于以下问题:PHP Time类的具体用法?PHP Time怎么用?PHP Time使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: findRecent

 /**
  * Custom finder method, returns recent to-do's based on status
  *
  * @param Query $query  cakephp query object
  * @param array $options list of options
  * @return query $query cakephp query object
  */
 public function findRecent(Query $query, array $options = ['status' => 0])
 {
     return $query->where(['is_done' => $options['status']])->order(['updated' => 'DESC'])->formatResults(function ($results, $query) {
         return $results->map(function ($row) {
             $timeCreated = new Time($row->created);
             $timeUpdated = new Time($row->updated);
             $row->created = $timeCreated->timeAgoInWords();
             $row->updated = $timeUpdated->timeAgoInWords();
             $row->todo = htmlspecialchars($row->todo);
             return $row;
         });
     });
 }
开发者ID:surjit,项目名称:todo,代码行数:20,代码来源:TodosTable.php

示例2: persianDate

 /**
  * @param string $format
  * @param int|string|DateTime $date
  * @return mixed|string
  */
 public function persianDate($date, $format = 'Y-m-d H:i:s')
 {
     $time = new Time($date);
     //        $unix = $time->i18nFormat(\IntlDateFormatter::FULL, 'Asia/Tehran', 'en_US')->toUnixString();
     //        debug($unix);die;
     return Persian::date($format, (int) $time->toUnixString(), '', 'Asia/Tehran', 'en');
 }
开发者ID:mohammadsaleh,项目名称:spider,代码行数:12,代码来源:SpiderHelper.php

示例3: testEnqueue

 /**
  * testEnqueue method.
  */
 public function testEnqueue()
 {
     $count = $this->EmailQueue->find()->count();
     $this->EmailQueue->enqueue('someone@domain.com', array('a' => 'variable', 'some' => 'thing'), array('subject' => 'Hey!', 'headers' => ['X-FOO' => 'bar', 'X-BAZ' => 'thing']));
     $this->assertEquals(++$count, $this->EmailQueue->find()->count());
     $result = $this->EmailQueue->find()->last()->toArray();
     $expected = array('email' => 'someone@domain.com', 'subject' => 'Hey!', 'template' => 'default', 'layout' => 'default', 'format' => 'both', 'template_vars' => array('a' => 'variable', 'some' => 'thing'), 'sent' => false, 'locked' => false, 'send_tries' => 0, 'config' => 'default', 'headers' => array('X-FOO' => 'bar', 'X-BAZ' => 'thing'), 'from_name' => null, 'from_email' => null);
     $sendAt = new Time($result['send_at']);
     unset($result['id'], $result['created'], $result['modified'], $result['send_at']);
     $this->assertEquals($expected, $result);
     $this->assertEquals(gmdate('Y-m-d H'), $sendAt->format('Y-m-d H'));
     $date = new Time();
     $this->EmailQueue->enqueue(array('a@example.com', 'b@example.com'), array('a' => 'b'), array('send_at' => $date, 'subject' => 'Hey!'));
     $this->assertEquals($count + 2, $this->EmailQueue->find()->count());
     $email = $this->EmailQueue->find()->where(array('email' => 'a@example.com'))->first();
     $this->assertEquals(array('a' => 'b'), $email['template_vars']);
     $this->assertEquals($date, $email['send_at']);
     $email = $this->EmailQueue->find()->where(array('email' => 'b@example.com'))->first();
     $this->assertEquals(array('a' => 'b'), $email['template_vars']);
     $this->assertEquals($date, $email['send_at']);
     $this->EmailQueue->enqueue('c@example.com', array('a' => 'c'), array('subject' => 'Hey', 'send_at' => $date, 'config' => 'other', 'template' => 'custom', 'layout' => 'email'));
     $email = $this->EmailQueue->find()->last();
     $this->assertEquals(array('a' => 'c'), $email['template_vars']);
     $this->assertEquals($date, $email['send_at']);
     $this->assertEquals('other', $email['config']);
     $this->assertEquals('custom', $email['template']);
     $this->assertEquals('email', $email['layout']);
 }
开发者ID:lorenzo,项目名称:cakephp-email-queue,代码行数:31,代码来源:EmailQueueTest.php

示例4: post

 public function post($body, $type, $id)
 {
     if (!$this->config('enabled')) {
         return false;
     }
     // Find out when the last time an announce was sent for this entity
     $result = $this->Slack->findAllByEntityAndEntityId($type, $id)->first();
     if ($result) {
         $last_update = $result->modified;
     } else {
         $result = $this->Slack->newEntity();
         $result->entity = $type;
         $result->entity_id = $id;
         $last_update = new Time('1 year ago');
     }
     // Prevent sending out an update too soon
     if ($last_update->wasWithinLast($this->config('debounce'))) {
         return false;
     }
     $http = new Client();
     $data = (object) ['text' => $body];
     $response = $http->post($this->config('webhook_url'), ['payload' => json_encode($data, JSON_PRETTY_PRINT)]);
     $result->messages++;
     $this->Slack->save($result);
 }
开发者ID:Cylindric,项目名称:edge,代码行数:25,代码来源:SlackComponent.php

示例5: display

 /**
  * {@inheritDoc}
  */
 public function display($fieldname, $dateValue, $model = null)
 {
     if (!is_object($dateValue)) {
         $dateValue = new Time($dateValue);
     }
     $dateValue->setTimezone('Europe/Berlin');
     return $dateValue->nice();
 }
开发者ID:codekanzlei,项目名称:cake-model-history,代码行数:11,代码来源:DateTransform.php

示例6: jobsPerSecond

 public function jobsPerSecond($conditions = [], $field = 'created', $time_range = '-1 hour')
 {
     $start_time = new Time($time_range);
     $current_time = new Time();
     $second_count = $current_time->diffInSeconds($start_time);
     $conditions[$this->aliasField($field) . ' > '] = $start_time;
     $count = $this->find()->where($conditions)->count();
     return $count / $second_count;
 }
开发者ID:uafrica,项目名称:delayed-jobs,代码行数:9,代码来源:DelayedJobsTable.php

示例7: jalaliAsiaTehranToGregorianUTC

 public static function jalaliAsiaTehranToGregorianUTC($date, $format = 'Y-m-d H:i:s')
 {
     $defaultTimezone = date_default_timezone_get();
     date_default_timezone_set('Asia/Tehran');
     $gregorianDate = formated_to_gregorian($date);
     $time = new Time($gregorianDate);
     date_default_timezone_set($defaultTimezone);
     return $time->setTimezone('UTC')->format($format);
 }
开发者ID:mohammadsaleh,项目名称:spider,代码行数:9,代码来源:SpiderTime.php

示例8: __construct

 /**
  * __construct to set up all properties and call parent
  *
  * @param string $fileName to initialize Environment file
  */
 public function __construct($fileName)
 {
     parent::__construct(Configure::read('CakePostman.environments.path') . $fileName);
     $environmentData = json_decode($this->read(), true);
     $this->environmentName = $environmentData['name'];
     $this->url = $environmentData['values'][0]['value'];
     $time = new Time($this->lastChange());
     $this->created = $time->nice();
 }
开发者ID:scherersoftware,项目名称:cake-postman,代码行数:14,代码来源:EnvironmentFile.php

示例9: testIndexAuthorizedWithPremium

 /**
  * Test index method unauthorized
  *
  * @return void
  */
 public function testIndexAuthorizedWithPremium()
 {
     $Users = TableRegistry::get('Users');
     $user = $Users->get(1);
     $time = new Time('+5 days');
     $user->end_subscription = $time;
     $Users->save($user);
     $this->session(['Auth' => ['User' => ['id' => 1, 'username' => 'mariano', 'avatar' => '../img/avatar.png', 'group_id' => 5]]]);
     $this->get(['controller' => 'premium', 'action' => 'index']);
     $this->assertResponseOk();
     //We can't test the flash test due to the translation system.
     $this->assertResponseContains('infobox-primary');
     $this->assertResponseContains($time->format('H:i:s d-m-Y'));
 }
开发者ID:edukondaluetg,项目名称:Xeta,代码行数:19,代码来源:PremiumControllerTest.php

示例10: beforeFilter

 public function beforeFilter(Event $event)
 {
     parent::beforeFilter($event);
     $session = $this->request->session();
     $lang = 'en';
     if (isset($this->request->params['lang'])) {
         $lang = $this->request->params['lang'];
     } else {
         if ($session->check('Config.language')) {
             $lang = $session->read('Config.language');
         }
     }
     $session->write('Config.language', $lang);
     // Change current language by post request
     if ($this->request->is('post') && isset($this->request->data['language'])) {
         $newLang = $this->request->data['language'];
         $transUrl = $this->translateUrl($newLang);
         $this->redirect($transUrl);
     }
     $this->set('lang', $lang);
     $this->set('controller', $this->name);
     I18n::locale($lang);
     Time::setToStringFormat('YYYY-MM-dd HH:mm:ss');
     Type::build('datetime')->useLocaleParser();
     $this->Auth->config(['unauthorizedRedirect' => false]);
     $this->Auth->allow(['login', 'init']);
     $user = $this->Auth->user();
     if (isset($user)) {
         $username = $user['username'];
         $this->set(['is_authorized' => true, 'username' => $username]);
     } else {
         $this->set('is_authorized', false);
     }
 }
开发者ID:GreeNoir,项目名称:game-wizard,代码行数:34,代码来源:AppController.php

示例11: subject

 /**
  * generate subject
  *
  * @access private
  * @author sakuragawa
  */
 private function subject($config, $errorType, $description)
 {
     $prefix = $config['mail']['prefix'];
     $date = Time::now()->format('Ymd H:i:s');
     $subject = $prefix . '[' . $date . '][' . strtoupper($errorType) . '][' . $this->url() . '] ' . $description;
     return $subject;
 }
开发者ID:fusic,项目名称:encount,代码行数:13,代码来源:Mail.php

示例12: forget

 /**
  * Allow a user to request a password reset.
  * @return
  */
 function forget()
 {
     $admin = TableRegistry::get('Admins');
     if ($this->request->data) {
         $admin_email = $this->request->data['email'];
         if (!empty($admin_email)) {
             $users = $admin->find('all', ['conditions' => ['Admins.email' => $admin_email]]);
             $user = $users->first();
             //echo $user->email;die;
             if (!$user) {
                 $this->Flash->success('Sorry, the username entered was not found.');
                 // $this->redirect('forget');
             } else {
                 //Time::$defaultLocale = 'es-ES';
                 $time = Time::now('Asia/Kolkata');
                 $time_new = $time->i18nFormat('yyyy-MM-dd HH:mm:ss');
                 $token = $user->id . "+" . $user->email . "+" . $time_new;
                 $token_new = base64_encode($token);
                 $subject = 'About';
                 $send = "<a href=" . $this->base . "/logins/reset?q=" . $token_new . ">click it </a>";
                 $sendto = $user->email;
                 $from = 'himani.arora@sdnainfotech.com';
                 $mailsent = $this->send_email($sendto, $from, $send, $subject);
                 if ($mailsent) {
                     return $this->redirect(['controller' => 'logins', 'action' => 'AfterForget']);
                 }
             }
         }
     }
 }
开发者ID:rashmi,项目名称:newrepo,代码行数:34,代码来源:LoginsController.php

示例13: updateCustomer

 public function updateCustomer()
 {
     $id = $this->request->params['pass']['0'];
     if (!$id) {
         $this->redirect(['controller' => 'customers', 'action' => 'listCustomer']);
     } else {
         $customersTable = TableRegistry::get('customers');
         $customer = $customersTable->newEntity();
         if ($this->request->is('POST')) {
             $data = $this->request->data;
             $customer = $customersTable->patchEntity($customer, $data, ['validate' => 'customer']);
             $customer->customer_id = $id;
             $customer->updated = Time::now();
             if ($customersTable->save($customer)) {
                 $this->redirect(['controller' => 'customers', 'action' => 'listCustomer']);
                 $this->Flash->success(__('Update recored ' . $id . ' customer !'));
             } else {
                 $this->Flash->error(__('Error data !'));
             }
         }
         $row_customer = $customersTable->find('all')->where(['customer_id' => $id])->first();
         $this->set('row_customer', $row_customer);
         $this->set('customer', $customer);
         $this->set('title', 'Update customer');
     }
 }
开发者ID:thanghexp,项目名称:project,代码行数:26,代码来源:CustomersController.php

示例14: render

    /**
     * Renders a date time widget.
     *
     * @param array $data Data to render with.
     * @param \Cake\View\Form\ContextInterface $context The current form context.
     * @return string A generated select box.
     * @throws \RuntimeException When option data is invalid.
     */
    public function render(array $data, ContextInterface $context)
    {
        $id = $data['id'];
        $name = $data['name'];
        $val = $data['val'];
        $type = $data['type'];
        $required = $data['required'] ? 'required' : '';
        $disabled = isset($data['disabled']) && $data['disabled'] ? 'disabled' : '';
        $role = isset($data['role']) ? $data['role'] : 'datetime-picker';
        $format = null;
        $locale = isset($data['locale']) ? $data['locale'] : I18n::locale();
        $timezoneAware = Configure::read('CrudView.timezoneAwareDateTimeWidget');
        $timestamp = null;
        $timezoneOffset = null;
        if (isset($data['data-format'])) {
            $format = $this->_convertPHPToMomentFormat($data['data-format']);
        }
        if (!$val instanceof DateTimeInterface && !empty($val)) {
            $val = $type === 'date' ? Time::parseDate($val) : Time::parseDateTime($val);
        }
        if ($val) {
            if ($timezoneAware) {
                $timestamp = $val->format('U');
                $dateTimeZone = new DateTimeZone(date_default_timezone_get());
                $timezoneOffset = $dateTimeZone->getOffset($val) / 60;
            }
            $val = $val->format($type === 'date' ? 'Y-m-d' : 'Y-m-d H:i:s');
        }
        if (!$format) {
            $format = $type === 'date' ? 'L' : 'L LT';
        }
        $widget = <<<html
            <div class="input-group {$type}">
                <input
                    type="text"
                    class="form-control"
                    name="{$name}"
                    value="{$val}"
                    id="{$id}"
                    role="{$role}"
                    data-locale="{$locale}"
                    data-format="{$format}"
html;
        if ($timezoneAware && isset($timestamp, $timezoneOffset)) {
            $widget .= <<<html
                    data-timestamp="{$timestamp}"
                    data-timezone-offset="{$timezoneOffset}"
html;
        }
        $widget .= <<<html
                    {$required}
                    {$disabled}
                />
                <label for="{$id}" class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </label>
            </div>
html;
        return $widget;
    }
开发者ID:friendsofcake,项目名称:crud-view,代码行数:68,代码来源:DateTimeWidget.php

示例15: setContentsFile

 public function setContentsFile()
 {
     $this->__contentsFileSettings();
     foreach ($this->__contentsFileSettings['fields'] as $field => $field_setting) {
         $file_info = $this->{$field};
         if (!empty($file_info) && array_key_exists('error', $file_info) && $file_info['error'] != UPLOAD_ERR_NO_FILE) {
             $file_set = ['model' => $this->_registryAlias, 'model_id' => $this->id, 'field_name' => $field, 'file_name' => $file_info['name'], 'file_content_type' => $file_info['type'], 'file_size' => $file_info['size'], 'file_error' => $file_info['error']];
             //$file_infoにtmp_nameがいるときはtmpディレクトリへのファイルのコピーを行う
             if (!empty($file_info['tmp_name'])) {
                 $tmp_file_name = Security::hash(rand() . Time::now()->i18nFormat('YYYY/MM/dd HH:ii:ss') . $file_info['name']);
                 if ($this->__getExt($file_info['name']) !== null) {
                     $tmp_file_name .= '.' . $this->__getExt($file_info['name']);
                 }
                 if (!copy($file_info['tmp_name'], $field_setting['cacheTempDir'] . $tmp_file_name)) {
                     //エラー
                 }
                 $file_set['tmp_file_name'] = $tmp_file_name;
             }
             //これを残して次に引き渡したくないので
             unset($this->{$field});
             $this->{'contents_file_' . $field} = $file_set;
         }
     }
     return $this;
 }
开发者ID:satthi,项目名称:contents-file,代码行数:25,代码来源:ContentsFileTrait.php


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