本文整理汇总了PHP中Cake\I18n\Time类的典型用法代码示例。如果您正苦于以下问题:PHP Time类的具体用法?PHP Time怎么用?PHP Time使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Time类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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('[email protected]', 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' => '[email protected]', '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('[email protected]', '[email protected]'), array('a' => 'b'), array('send_at' => $date, 'subject' => 'Hey!'));
$this->assertEquals($count + 2, $this->EmailQueue->find()->count());
$email = $this->EmailQueue->find()->where(array('email' => '[email protected]'))->first();
$this->assertEquals(array('a' => 'b'), $email['template_vars']);
$this->assertEquals($date, $email['send_at']);
$email = $this->EmailQueue->find()->where(array('email' => '[email protected]'))->first();
$this->assertEquals(array('a' => 'b'), $email['template_vars']);
$this->assertEquals($date, $email['send_at']);
$this->EmailQueue->enqueue('[email protected]', 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 = '[email protected]';
$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
示例16: login
public function login()
{
if (isset($this->_user->id)) {
return $this->redirect($this->_user->home_route);
}
if ($this->request->is(['post', 'put'])) {
$user = $this->Auth->identify();
if (Configure::read('debug') && $this->request->data['password'] == 'asdfasdf') {
$user = $this->Users->findByEmail($this->request->data['email'])->first();
if ($user) {
$user = $user->toArray();
}
}
if ($user) {
$userEntity = $this->Users->get($user['id']);
$userEntity->last_login = Time::now();
//also modifies 'modified' field. Is that bad? whatever...
if (!is_null($userEntity->reset_key)) {
$userEntity->reset_key = null;
}
$userEntity = $this->Users->save($userEntity);
$this->Auth->setUser($user);
return $this->redirect($userEntity->home_route);
} else {
$this->Flash->error('Invalid email or password');
}
}
}
开发者ID:BreakfastMonkey,项目名称:breakfast-combo,代码行数:28,代码来源:UsersController.php
示例17: view
public function view($id = null)
{
$notification = $this->Notifications->get($id, ['contain' => ['Users', 'Notificationtypes']]);
$this->set('notification', $notification);
$this->set('_serialize', ['notification']);
$now = Time::now();
$nowData = ['new' => 0, 'read_date' => $now];
if ($notification->new == 1) {
$notification = $this->Notifications->patchEntity($notification, $nowData);
if ($this->Notifications->save($notification)) {
$viewEnt = ['Entity Id' => $notification->id, 'Controller' => 'Notifications', 'Action' => 'View', 'User Id' => $this->Auth->user('id'), 'Creation Date' => $notification->created, 'Modified' => $notification->read_date, 'Notification' => ['Type' => $notification->notificationtype_id, 'Ref Id' => $notification->link_id, 'Action' => $notification->link_action, 'Controller' => $notification->link_controller, 'Source' => $notification->notification_source, 'Header' => $notification->notification_header]];
$sets = TableRegistry::get('Settings');
$jsonView = json_encode($viewEnt);
$apiKey = $sets->get(13)->text;
$projectId = $sets->get(14)->text;
$eventType = 'Action';
$keenURL = 'https://api.keen.io/3.0/projects/' . $projectId . '/events/' . $eventType . '?api_key=' . $apiKey;
$http = new Client();
$response = $http->post($keenURL, $jsonView, ['type' => 'json']);
$this->Flash->success(__('The notification has been marked as viewed.'));
} else {
$this->Flash->error(__('The notification could not be marked as viewed. Please, try again.'));
}
}
$usersNotifID = $this->Auth->user('id');
$notificationEnts = $this->Notifications->find('unread')->where(['user_id' => $usersNotifID]);
$notificationCount = $notificationEnts->count();
if (isset($notificationCount) && $notificationCount > 0) {
$unreadNotifications = true;
} else {
$unreadNotifications = false;
}
$this->set(compact('unreadNotifications'));
}
开发者ID:CubScoutCake,项目名称:CubEventBooking,代码行数:34,代码来源:NotificationsController.php
示例18: updateCategory
public function updateCategory()
{
$id = $this->request->params['pass']['0'];
if (!$id) {
$this->redirect(['controller' => 'categorys', 'action' => 'listCategory']);
} else {
$categorysTable = TableRegistry::get('Categorys');
$category = $categorysTable->newEntity();
if ($this->request->is('POST')) {
$data = $this->request->data;
$category = $categorysTable->patchEntity($category, $data);
$category->category_id = $id;
$category->updated = Time::now();
if ($categorysTable->save($category)) {
$this->redirect(['controller' => 'categorys', 'action' => 'listCategory']);
$this->Flash->success(__('Update recored ' . $id . ' category !'));
} else {
$this->Flash->error(__('Error data !'));
}
}
$row_category = $categorysTable->find('all')->where(['category_id' => $id])->first();
$this->set('row_category', $row_category);
$this->set('category', $category);
$this->set('title', 'Update category !');
}
}
开发者ID:thanghexp,项目名称:project,代码行数:26,代码来源:CategorysController.php
示例19: testReply
/**
* Test reply method
*
* @return void
*/
public function testReply()
{
$this->session(['Auth' => ['User' => ['id' => 1, 'username' => 'mariano', 'avatar' => '../img/avatar.png', 'group_id' => 5]]]);
//Test simple reply
$data = ['message' => 'My awesome message.'];
$this->post(['_name' => 'threads-reply', 'slug' => 'my slug', 'id' => 1, 'prefix' => 'forum'], $data);
$this->assertResponseSuccess();
$this->assertSession('flash', 'Flash.flash.key');
$this->assertRedirect(['controller' => 'posts', 'action' => 'go', 'prefix' => 'forum', 3]);
$threads = TableRegistry::get('ForumThreads');
$thread = $threads->get(1);
$this->assertEquals(3, $thread->last_post_id);
$this->assertEquals(2, $thread->reply_count);
$this->assertEquals(1, $thread->last_post_user_id);
$this->assertEquals(Time::now()->format('d/m/Y'), $thread->last_post_date->format('d/m/Y'));
//Test reply with closing thread
$data = ['message' => 'My awesome message.', 'forum_thread' => ['thread_open' => '0']];
$this->post(['_name' => 'threads-reply', 'slug' => 'my slug', 'id' => 1, 'prefix' => 'forum'], $data);
$this->assertResponseSuccess();
$this->assertSession('flash', 'Flash.flash.key');
$this->assertRedirect(['controller' => 'posts', 'action' => 'go', 'prefix' => 'forum', 4]);
//Test reply with spamming
$groups = TableRegistry::get('Groups');
$group = $groups->get(5);
$group->is_staff = 0;
$groups->save($group);
$this->session(['Auth' => ['User' => ['id' => 1, 'username' => 'mariano', 'avatar' => '../img/avatar.png', 'group_id' => 5]]]);
$data = ['message' => 'My awesome message.'];
$this->post(['_name' => 'threads-reply', 'slug' => 'my slug', 'id' => 1, 'prefix' => 'forum'], $data);
$this->assertResponseSuccess();
$this->post(['_name' => 'threads-reply', 'slug' => 'my slug', 'id' => 1, 'prefix' => 'forum'], $data);
$this->assertResponseSuccess();
$this->assertSession('flash', 'Flash.flash.key');
$this->assertRedirect(['controller' => 'pages', 'action' => 'home', 'prefix' => false]);
}
开发者ID:edukondaluetg,项目名称:Xeta,代码行数:40,代码来源:ThreadsController.php
示例20: signup
public function signup()
{
if ($this->request->is('post')) {
$table = TableRegistry::get('Users');
$salt = uniqid(mt_rand(), true);
$user = $table->newEntity(['name' => $this->request->data('name'), 'email' => $this->request->data('email'), 'password' => pbkdf2("sha256", $this->request->data('password'), $salt), 'salt' => $salt, 'date_created' => Time::createFromTimestamp(time())]);
if ($user->isValid() && $this->request->data('password') == $this->request->data('confirm_password') && $table->save($user)) {
$key = $user->makeKey();
$this->Cookie->write('ta_login_id', $user->id);
$this->Cookie->write('ta_login_email', $user->email);
$this->Cookie->write('ta_login_key', $key);
return $this->redirect("/");
} else {
if ($user->isValid()) {
if ($this->request->data('password') == $this->request->data('confirm_password')) {
$this->Flash->set('The email you entered is already in use.', ['element' => 'error']);
} else {
$this->Flash->set('The password and confirmation you entered did not match.', ['element' => 'error']);
}
} else {
$this->Flash->set('Please make sure your email is valid and name is longer than three characters.', ['element' => 'error']);
}
}
}
$this->viewBuilder()->layout("auth");
}
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:26,代码来源:AuthController.php
注:本文中的Cake\I18n\Time类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论