本文整理汇总了PHP中Cake\I18n\Time::i18nFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP Time::i18nFormat方法的具体用法?PHP Time::i18nFormat怎么用?PHP Time::i18nFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\I18n\Time
的用法示例。
在下文中一共展示了Time::i18nFormat方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testI18nFormat
/**
* test formatting dates taking in account preferred i18n locale file
*
* @return void
*/
public function testI18nFormat()
{
$time = new Time('Thu Jan 14 13:59:28 2010');
$result = $time->i18nFormat();
$expected = '1/14/10, 1:59 PM';
$this->assertTimeFormat($expected, $result);
$result = $time->i18nFormat(\IntlDateFormatter::FULL, null, 'es-ES');
$expected = 'jueves, 14 de enero de 2010, 13:59:28 (GMT)';
$this->assertTimeFormat($expected, $result);
$format = [\IntlDateFormatter::NONE, \IntlDateFormatter::SHORT];
$result = $time->i18nFormat($format);
$expected = '1:59 PM';
$this->assertTimeFormat($expected, $result);
$result = $time->i18nFormat('HH:mm:ss', 'Australia/Sydney');
$expected = '00:59:28';
$this->assertTimeFormat($expected, $result);
Time::$defaultLocale = 'fr-FR';
$result = $time->i18nFormat(\IntlDateFormatter::FULL);
$expected = 'jeudi 14 janvier 2010 13:59:28 UTC';
$this->assertTimeFormat($expected, $result);
$result = $time->i18nFormat(\IntlDateFormatter::FULL, null, 'es-ES');
$expected = 'jueves, 14 de enero de 2010, 13:59:28 (GMT)';
$this->assertTimeFormat($expected, $result, 'DEfault locale should not be used');
}
示例2: testI18nFormatWithOffsetTimezone
/**
* test formatting dates with offset style timezone
*
* @see https://github.com/facebook/hhvm/issues/3637
* @return void
*/
public function testI18nFormatWithOffsetTimezone()
{
$time = new Time('2014-01-01T00:00:00+00');
$result = $time->i18nFormat(\IntlDateFormatter::FULL);
$expected = 'Wednesday January 1 2014 12:00:00 AM GMT';
$this->assertTimeFormat($expected, $result);
$time = new Time('2014-01-01T00:00:00+09');
$result = $time->i18nFormat(\IntlDateFormatter::FULL);
$expected = 'Wednesday January 1 2014 12:00:00 AM GMT+09:00';
$this->assertTimeFormat($expected, $result);
$time = new Time('2014-01-01T00:00:00-01:30');
$result = $time->i18nFormat(\IntlDateFormatter::FULL);
$expected = 'Wednesday January 1 2014 12:00:00 AM GMT-01:30';
$this->assertTimeFormat($expected, $result);
}
示例3: i18nFormat
/**
* Returns a formatted date string, given either a Datetime instance,
* UNIX timestamp or a valid strtotime() date string.
*
* @param int|string|\DateTime $date UNIX timestamp, strtotime() valid string or DateTime object
* @param string|null $format Intl compatible format string.
* @param bool|string $invalid Default value to display on invalid dates
* @param string|\DateTimeZone|null $timezone User's timezone string or DateTimeZone object
* @return string Formatted and translated date string
* @throws \InvalidArgumentException When the date cannot be parsed
* @see \Cake\I18n\Time::i18nFormat()
*/
public function i18nFormat($date, $format = null, $invalid = false, $timezone = null)
{
if (!isset($date)) {
return $invalid;
}
try {
$time = new Time($date, $timezone);
return $time->i18nFormat($format, $timezone);
} catch (\Exception $e) {
if ($invalid === false) {
throw $e;
}
return $invalid;
}
}
示例4: indexByDate
/**
* List posts for a specific date:
*
* The date must be passed in the format:
* <pre>YYYY/MM/dd</pre>
* The month and day are optional.
* You can also use the special keywords "today" and "yesterday".
*
* Examples:
* <pre>/posts/2016/06/11</pre>
* <pre>/posts/2016/06</pre>
* <pre>/posts/2016</pre>
* <pre>/posts/today</pre>
* <pre>/posts/yesterday</pre>
* @param string $date Date as `YYYY/MM/dd`
* @return \Cake\Network\Response|null|void
*/
public function indexByDate($date = null)
{
//Data can be passed as query string, from a widget
if ($this->request->query('q')) {
return $this->redirect([$this->request->query('q')]);
}
//Sets `$year`, `$month` and `$day`
//`$month` and `$day` may be `null`
if ($date === 'today' || $date === 'yesterday') {
$date = new Time($date === 'today' ? 'now' : '1 days ago');
list($year, $month, $day) = explode('/', $date->i18nFormat('YYYY/MM/dd'));
} else {
list($year, $month, $day) = am(explode('/', $date), [null, null, null]);
}
//Sets the start date
$start = (new Time())->setDate($year, empty($month) ? 1 : $month, empty($day) ? 1 : $day)->setTime(0, 0, 0);
//Sets the end date
if ($year && $month && $day) {
$end = (new Time($start))->addDay(1);
} elseif ($year && $month) {
$end = (new Time($start))->addMonth(1);
} else {
$end = (new Time($start))->addYear(1);
}
$page = $this->request->query('page') ? $this->request->query('page') : 1;
//Sets the cache name
$cache = sprintf('index_date_%s_limit_%s_page_%s', md5(serialize([$start, $end])), $this->paginate['limit'], $page);
//Tries to get data from the cache
list($posts, $paging) = array_values(Cache::readMany([$cache, sprintf('%s_paging', $cache)], $this->Posts->cache));
//If the data are not available from the cache
if (empty($posts) || empty($paging)) {
$query = $this->Posts->find('active')->contain(['Categories' => function ($q) {
return $q->select(['title', 'slug']);
}, 'Tags' => function ($q) {
return $q->order(['tag' => 'ASC']);
}, 'Users' => function ($q) {
return $q->select(['first_name', 'last_name']);
}])->select(['id', 'title', 'subtitle', 'slug', 'text', 'created'])->where([sprintf('%s.created >=', $this->Posts->alias()) => $start, sprintf('%s.created <', $this->Posts->alias()) => $end])->order([sprintf('%s.created', $this->Posts->alias()) => 'DESC']);
$posts = $this->paginate($query)->toArray();
//Writes on cache
Cache::writeMany([$cache => $posts, sprintf('%s_paging', $cache) => $this->request->param('paging')], $this->Posts->cache);
//Else, sets the paging parameter
} else {
$this->request->params['paging'] = $paging;
}
$this->set(compact('posts', 'year', 'month', 'day'));
}
示例5: createExam
/**
* @param Connection $dbConnection
* @param array $exam
* @author team_syzzygy
*/
public function createExam(Connection $dbConnection, array $examConfig)
{
$examTable = $this->getExamReference();
$exam = $examTable->newEntity();
//Debugger::dump($examConfig);
$exam->Exam_Level = $examConfig['Exam_Level'];
$exam_date = new Time($examConfig['Exam_Date']);
$exam->Exam_Date = $exam_date->i18nFormat('YYYY-MM-dd');
$exam->Exam_Year = $exam_date->i18nFormat('YYYY');
$exam->Enabled = $examConfig['Enabled'];
$registration_deadline = new Time($examConfig['Registration_Deadline']);
$exam->Registration_Deadline = $registration_deadline->i18nFormat('YYYY-MM-dd');
$deferment_deadline = new Time($examConfig['Deferment_Deadline']);
$exam->Deferment_Deadline = $deferment_deadline->i18nFormat('YYYY-MM-dd');
$exam->US_Enrollment_Fee = $examConfig['US_Enrollment_Fee'];
$exam->International_Enrollment_Fee = $examConfig['International_Enrollment_Fee'];
$exam->US_Retest_Fee_Current_Year = $examConfig['US_Retest_Fee_Current_Year'];
$exam->US_Retest_Fee_Next_Year = $examConfig['US_Retest_Fee_Next_Year'];
$exam->US_Deferment_Fee_Before_Deadline = $examConfig['US_Deferment_Fee_Before_Deadline'];
$exam->US_Deferment_Fee_After_Deadline = $examConfig['US_Deferment_Fee_After_Deadline'];
$exam->International_Retest_Fee_Current_Year = $examConfig['International_Retest_Fee_Current_Year'];
$exam->International_Retest_Fee_Next_Year = $examConfig['International_Retest_Fee_Next_Year'];
$exam->International_Deferment_Fee_Before_Deadline = $examConfig['International_Deferment_Fee_Before_Deadline'];
$exam->International_Deferment_Fee_After_Deadline = $examConfig['International_Deferment_Fee_After_Deadline'];
$exam->Exam_Passing_Score = $examConfig['Exam_Passing_Score'];
if (!empty($examConfig['Note'])) {
$exam->Note = $examConfig['Note'];
}
//Debugger::dump($examConfig);
$examLocations = array();
for ($i = 0; $i < count($examConfig['Locations']); $i++) {
$examEntity = $examTable->ExaminationLocationT->newEntity();
$examEntity->Location_Name = $examConfig['Locations'][$i];
$examEntity->System_Date_Time = time();
if (strcmp($examConfig['Locations'][$i], "Other-SeeNote") == 0) {
$examEntity->Note = $examConfig['ExamLocationNote'];
}
$examLocations[$i] = $examEntity;
}
$exam->examLocationInfo = $examLocations;
if ($examTable->save($exam)) {
return true;
} else {
return false;
}
}
示例6: _callFitbit
public function _callFitbit($data, $type, $associated_date = null)
{
$client_id = '227LW5';
$client_secret = '956867a253723f4aa763b0ec013bc8a6';
$header_params = [];
$link = $method = '';
if ($type == 'refresh_token' or $type == 'authorization_code') {
$header_params = ['Authorization' => 'Basic ' . base64_encode($client_id . ':' . $client_secret), 'Content-Type' => 'application/x-www-form-urlencoded'];
$link = 'https://api.fitbit.com/oauth2/token';
if ($type == 'refresh_token') {
$params = ['grant_type' => 'refresh_token', 'refresh_token' => $data['token_secret']];
} else {
$params = ['client_id' => $client_id, 'grant_type' => 'authorization_code', 'code' => $data, 'redirect_uri' => 'http://localhost.statbro.com/fitbit-auth.json'];
}
$method = 'post';
} else {
if ($type == 'subscribe') {
//data is the response from convert fitbit
$header_params = ['Authorization' => 'Bearer ' . $data['token'], 'Content-Type' => 'application/x-www-form-urlencoded', 'X-Fitbit-Subscriber-Id' => 1];
$params = [];
$link = 'https://api.fitbit.com/1/user/-/activities/apiSubscriptions/' . $this->Auth->user('id') . '.json';
$method = 'post';
} else {
$header_params = ['Authorization' => 'Bearer ' . $data->token, 'Content-Type' => 'application/x-www-form-urlencoded'];
$params = [];
if ($type == 'activities') {
$link = 'https://api.fitbit.com/1/user/-/activities/date/' . Time::now()->i18nFormat('yyyy-MM-dd') . '.json';
} elseif ($type == 'steps_in_week') {
$link = 'https://api.fitbit.com/1/user/-/activities/steps/date/today/1w.json';
} elseif ($type == 'steps_yesterday') {
$yesterday = Time::now()->subDays(1);
$link = 'https://api.fitbit.com/1/user/-/activities/steps/date/' . $yesterday->i18nFormat('yyyy-MM-dd') . '/1d.json';
} elseif ($type == 'steps_today') {
$link = 'https://api.fitbit.com/1/user/-/activities/steps/date/' . Time::now()->i18nFormat('yyyy-MM-dd') . '/1d.json';
} elseif ($type == 'steps') {
$day = new Time($associated_date);
if (!$day) {
return false;
}
$link = 'https://api.fitbit.com/1/user/-/activities/steps/date/' . $day->i18nFormat('yyyy-MM-dd') . '/1d.json';
} elseif ($type == 'steps_past_3_days') {
$now = Time::now();
$three_days_ago = Time::now()->subDays(3);
$link = 'https://api.fitbit.com/1/user/-/activities/steps/date/' . $three_days_ago->i18nFormat('yyyy-MM-dd') . '/' . $now->i18nFormat('yyyy-MM-dd') . '.json';
}
$method = 'get';
}
}
$http = new Client(['headers' => $header_params]);
if (!$link or !$method) {
return false;
}
return $http->{$method}($link, $params);
}