本文整理汇总了PHP中Cake\I18n\Time::format方法的典型用法代码示例。如果您正苦于以下问题:PHP Time::format方法的具体用法?PHP Time::format怎么用?PHP Time::format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\I18n\Time
的用法示例。
在下文中一共展示了Time::format方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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']);
}
示例2: 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'));
}
示例3: testTimeAgoInWordsNegativeValues
/**
* test timeAgoInWords() with negative values.
*
* @return void
*/
public function testTimeAgoInWordsNegativeValues()
{
$time = new Time('-2 months -2 days');
$result = $time->timeAgoInWords(['end' => '3 month']);
$this->assertEquals('2 months, 2 days ago', $result);
$time = new Time('-2 months -2 days');
$result = $time->timeAgoInWords(['end' => '3 month']);
$this->assertEquals('2 months, 2 days ago', $result);
$time = new Time('-2 months -2 days');
$result = $time->timeAgoInWords(['end' => '1 month', 'format' => 'yyyy-MM-dd']);
$this->assertEquals('on ' . date('Y-m-d', strtotime('-2 months -2 days')), $result);
$time = new Time('-2 years -5 months -2 days');
$result = $time->timeAgoInWords(['end' => '3 years']);
$this->assertEquals('2 years, 5 months, 2 days ago', $result);
$time = new Time('-2 weeks -2 days');
$result = $time->timeAgoInWords(['format' => 'yyyy-MM-dd']);
$this->assertEquals('2 weeks, 2 days ago', $result);
$time = new Time('-3 years -12 months');
$result = $time->timeAgoInWords();
$expected = 'on ' . $time->format('n/j/y');
$this->assertEquals($expected, $result);
$time = new Time('-1 month -1 week -6 days');
$result = $time->timeAgoInWords(['end' => '1 year', 'accuracy' => ['month' => 'month']]);
$this->assertEquals('1 month ago', $result);
$time = new Time('-1 years -2 weeks -3 days');
$result = $time->timeAgoInWords(['accuracy' => ['year' => 'year']]);
$expected = 'on ' . $time->format('n/j/y');
$this->assertEquals($expected, $result);
$time = new Time('-13 months -5 days');
$result = $time->timeAgoInWords(['end' => '2 years']);
$this->assertEquals('1 year, 1 month, 5 days ago', $result);
$time = new Time('-58 minutes');
$result = $time->timeAgoInWords(['accuracy' => 'hour']);
$this->assertEquals('about an hour ago', $result);
$time = new Time('-23 hours');
$result = $time->timeAgoInWords(['accuracy' => 'day']);
$this->assertEquals('about a day ago', $result);
}
示例4: _delete
/**
* Sets a cookie expire time to remove cookie value.
*
* This is only done once all values in a cookie key have been
* removed with delete.
*
* @param string $name Name of cookie
* @return void
*/
protected function _delete($name)
{
$config = $this->configKey($name);
$expires = new Time('now');
$this->_response->cookie(array('name' => $name, 'value' => '', 'expire' => $expires->format('U') - 42000, 'path' => $config['path'], 'domain' => $config['domain'], 'secure' => $config['secure'], 'httpOnly' => $config['httpOnly']));
}
示例5: _setCookie
/**
* Set the cookie in the response.
*
* Also sets the request->params['_csrfToken'] so the newly minted
* token is available in the request data.
*
* @param \Cake\Network\Request $request The request object.
* @param \Cake\Network\Response $response The response object.
* @return void
*/
protected function _setCookie(Request $request, Response $response)
{
$expiry = new Time($this->_config['expiry']);
$value = hash('sha512', Security::randomBytes(16), false);
$request->params['_csrfToken'] = $value;
$response->cookie(['name' => $this->_config['cookieName'], 'value' => $value, 'expire' => $expiry->format('U'), 'path' => $request->webroot, 'secure' => $this->_config['secure'], 'httpOnly' => $this->_config['httpOnly']]);
}
示例6: testMarshalWithLocaleParsingWithFormat
/**
* Tests marshalling dates using the locale aware parser and custom format
*
* @return void
*/
public function testMarshalWithLocaleParsingWithFormat()
{
$this->type->useLocaleParser()->setLocaleFormat('dd MMM, y');
$expected = new Time('13-10-2013');
$result = $this->type->marshal('13 Oct, 2013');
$this->assertEquals($expected->format('Y-m-d'), $result->format('Y-m-d'));
}
示例7: testWriteArrayValues
/**
* test writing values that are not scalars
*
* @return void
*/
public function testWriteArrayValues()
{
$this->Cookie->write('Testing', [1, 2, 3]);
$expected = ['name' => 'Testing', 'value' => '[1,2,3]', 'path' => '/', 'domain' => '', 'secure' => false, 'httpOnly' => false];
$result = $this->Controller->response->cookie('Testing');
$time = new Time('now');
$this->assertWithinRange($time->format('U') + 10, $result['expire'], 1);
unset($result['expire']);
$this->assertEquals($expected, $result);
}
示例8: testMarshalWithLocaleParsing
/**
* Tests marshalling dates using the locale aware parser
*
* @return void
*/
public function testMarshalWithLocaleParsing()
{
$this->type->useLocaleParser();
$expected = new Time('23:23:00');
$result = $this->type->marshal('11:23pm');
$this->assertEquals($expected->format('H:i'), $result->format('H:i'));
$this->assertNull($this->type->marshal('derp:23'));
}
示例9: _setCookie
/**
* Set the cookie in the response.
*
* Also sets the request->params['_csrfToken'] so the newly minted
* token is available in the request data.
*
* @param \Cake\Network\Request $request The request object.
* @param \Cake\Network\Response $response The response object.
* @return void
*/
protected function _setCookie(Request $request, Response $response)
{
$expiry = new Time($this->_config['expiry']);
$value = Security::hash(Text::uuid(), 'sha1', true);
$request->params['_csrfToken'] = $value;
$response->cookie(['name' => $this->_config['cookieName'], 'value' => $value, 'expire' => $expiry->format('U'), 'path' => $request->webroot, 'secure' => $this->_config['secure']]);
}
示例10: getDayUtc
/**
* Get datetime range for today from at 00:00:00 to 23:59:59
*
* @return none
*/
public function getDayUtc($date, &$start, &$end, $localTimezone)
{
// get the date/time in local timezone
$day = new Time($date, $localTimezone);
$start = new Time($day->format("Y/m/d"), "America/Chicago");
// peel off the time, leave the date only
$end = new Time($day->format("Y/m/d 23:59:59"), "America/Chicago");
// change them to utc for the
$start->timezone = "UTC";
$end->timezone = "UTC";
//debug($start);
//debug($end);
//die;
}
示例11: indexToday
/**
* Index method
*
* @return void
*/
public function indexToday($dayOffset = 0)
{
$dayStart = null;
$dayEnd = null;
$this->getDay($dayOffset, $dayStart, $dayEnd, "America/Chicago");
$query = $this->Sessions->find()->where(['Sessions.created >=' => $dayStart])->where(['Sessions.created <=' => $dayEnd])->contain(['Users', 'Projects', 'Tasks'])->order(['Sessions.created' => 'DESC']);
// this is just total elapsed time for the day not a real datetime
$totalTime = new Time('2000-01-01');
//debug($totalTime);
$recs = $query->toArray();
//debug($recs);die;
$index = 0;
foreach ($recs as $session) {
$start = new Time($session['created']);
$stop = new Time($session['stopped']);
$interval = $start->diff($stop);
$totalTime->add($interval);
// if elapsed time is more than 0 days, show the day part too
if ($interval->days > 0) {
$timeLapse = $interval->format('%D:%H:%I');
} else {
$timeLapse = $interval->format('%H:%I');
}
// just show MM:SS
/* show state */
if ($session->state == 0) {
$state = "not started";
} else {
if ($session->state == 1) {
$state = "<span style='font-weight: normal;'>STARTED</span>";
} else {
if ($session->state == 2) {
$state = "stopped";
} else {
$state = "invalid";
}
}
}
$recs[$index]['timeLapse'] = $timeLapse;
$recs[$index]['totalTime'] = $totalTime->format('H:i');
$recs[$index]['stateDesc'] = $state;
$index++;
}
$this->set('sessions', $recs);
$this->set('totalTime', $totalTime);
//debug($sessions);die;
$this->set('_serialize', ['sessions']);
}
示例12: patternevent
public function patternevent($id = null)
{
$patterns = TableRegistry::get('Patterns');
$events = TableRegistry::get('Events');
$employee_id = $this->request->query('employee_id');
$patternparent_id = $this->request->query('patternparentid');
$pattern_sun = $this->request->query('patternSun');
$pattern_mon = $this->request->query('patternMon');
$pattern_tue = $this->request->query('patternTue');
$pattern_wed = $this->request->query('patternWed');
$pattern_thu = $this->request->query('patternThu');
$pattern_fri = $this->request->query('patternFri');
$pattern_sat = $this->request->query('patternSat');
$pattern_id = $this->request->query('id');
$dowMap = array('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat');
// delete exisitng events for current patternParent
// prior to creating events
$events_to_delete = [$pattern_sun, $pattern_mon, $pattern_tue, $pattern_wed, $pattern_thu, $pattern_fri, $pattern_sat];
foreach ($events_to_delete as $key => $value) {
$events->deleteAll(['pattern_id' => $value]);
}
$query = $patterns->find('all', ['conditions' => ['pattern_parent_id' => $patternparent_id], 'contain' => ['Resources', 'Employees']]);
foreach ($query as $row) {
//debug($row->toArray());
$eventsTable = TableRegistry::get('Events');
// day of week
$byweekday = $dowMap[$row['day_of_week'] - 1];
// start date
$patternend = new \DateTime($row['start_date']);
// every n weeks
$step = $row->week_of_year;
// start date offset
$starting_on = $row->starting_on - 1;
foreach (getPatternDays($row['start_date'], $byweekday, $step, $starting_on, $row['end_date']) as $patternDay) {
// create date schedule array
$timezone = 'UTC';
$event = $eventsTable->newEntity();
if (!empty($query)) {
//loop through patterns to
//create all events based on current employee id and current pattern(s)
//save to db
//$count_of_leave_entitlement++;
//format start and end dates including adding start / end hours and minutes
$starthours = date('H', strtotime($row->resource->start_time));
$startmins = date('i', strtotime($row->resource->start_time));
$start = new Time($patternDay->format("Y-m-d"));
$start->modify('+' . $starthours . ' hours');
$start->modify('+' . $startmins . ' minutes');
$endhours = date('H', strtotime($row->resource->end_time));
$endmins = date('i', strtotime($row->resource->end_time));
$end = new Time($patternDay->format("Y-m-d"));
if ($row->resource->night_shift == 1) {
$end->modify('+ 1 day');
}
$end->modify('+' . $endhours . ' hours');
$end->modify('+' . $endmins . ' minutes');
// event model to save
$event->title = $row->employee->first_name[0] . ' ' . $row->employee->last_name;
$event->startdate = $start->format('Y-m-d H:i:s');
$event->enddate = $end->format('Y-m-d H:i:s');
$event->allDay = $row->resource->allDay;
$event->pattern_id = $row->id;
$event->resource_id = $row->resource_id;
$event->employee_id = $row->employee->id;
$event->event_type = 'pattern';
$event->patternparentid = $patternparent_id;
$eventsTable->save($event);
} else {
$this->Flash->error(__('The events could not be saved. Please, try again.'));
}
}
}
$this->Flash->success(__('The events have been saved.'));
return $this->redirect($this->referer());
$this->autoRender = false;
}