本文整理汇总了PHP中Carbon\Carbon::createFromTimestampUTC方法的典型用法代码示例。如果您正苦于以下问题:PHP Carbon::createFromTimestampUTC方法的具体用法?PHP Carbon::createFromTimestampUTC怎么用?PHP Carbon::createFromTimestampUTC使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carbon\Carbon
的用法示例。
在下文中一共展示了Carbon::createFromTimestampUTC方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCount
/**
* Show the application dashboard.
*
* @return Response
*/
public function getCount(\Illuminate\Http\Request $request)
{
// Validate API Key
$apiKey = \App\Models\ApiKey::where('api_key', $request->get('apiKey'))->where('active', 1)->first();
if (!$apiKey) {
return \Response::json(['status' => 'Error', 'error' => 'Invalid API Key.'], 401);
}
// Validate Data
if (!$request->has('name')) {
return \Response::json(['status' => 'Error', 'error' => 'The name field is required.'], 400);
}
if (!$request->has('count') && !$request->has('value')) {
return \Response::json(['status' => 'Error', 'error' => 'Either the count or value field is required.'], 400);
}
$user = $apiKey->user;
$counter = $user->counters()->where('name', $request->get('name'))->first();
if (!$counter) {
$counter = \App\Models\Counter::create(['user_id' => $user->id, 'name' => $request->get('name'), 'type' => $request->has('count') ? \App\Models\Counter::CounterTypeCount : \App\Models\Counter::CounterTypeValue]);
} else {
if ($counter->type == \App\Models\Counter::CounterTypeCount && !$request->has('count')) {
return \Response::json(['status' => 'Error', 'error' => 'Stat "' . $request->get('name') . '" already exists and is a counter stat, but the "count" field was not included.'], 422);
}
if ($counter->type == \App\Models\Counter::CounterTypeValue && !$request->has('value')) {
return \Response::json(['status' => 'Error', 'error' => 'Stat "' . $request->get('name') . '" already exists and is a value stat, but the "value" field was not included.'], 422);
}
}
$bean = \App\Models\Bean::create(['counter_id' => $counter->id, 'value' => $counter->type == \App\Models\Counter::CounterTypeCount ? $request->get('count') : $request->get('value')]);
if ($request->has('timestamp')) {
$bean->created_at = \Carbon\Carbon::createFromTimestampUTC($request->get('timestamp'));
$bean->save();
}
return \Response::json(['status' => 'Success'], 200);
}
示例2: logToConsole
public function logToConsole($tx_event)
{
if ($_debugLogTxTiming = Config::get('xchain.debugLogTxTiming')) {
PHP_Timer::start();
}
if (!isset($GLOBALS['XCHAIN_GLOBAL_COUNTER'])) {
$GLOBALS['XCHAIN_GLOBAL_COUNTER'] = 0;
}
$count = ++$GLOBALS['XCHAIN_GLOBAL_COUNTER'];
$xcp_data = $tx_event['counterpartyTx'];
if ($tx_event['network'] == 'counterparty') {
if ($xcp_data['type'] == 'send') {
$this->wlog("from: {$xcp_data['sources'][0]} to {$xcp_data['destinations'][0]}: {$xcp_data['quantity']} {$xcp_data['asset']} [{$tx_event['txid']}]");
} else {
$this->wlog("[" . date("Y-m-d H:i:s") . "] XCP TX FOUND: {$xcp_data['type']} at {$tx_event['txid']}");
}
} else {
if (rand(1, 100) === 1) {
$c = Carbon::createFromTimestampUTC(floor($tx_event['timestamp']))->timezone(new \DateTimeZone('America/Chicago'));
$this->wlog("heard {$count} tx. Last tx time: " . $c->format('Y-m-d h:i:s A T'));
}
}
if ($_debugLogTxTiming) {
Log::debug("[" . getmypid() . "] Time for logToConsole: " . PHP_Timer::secondsToTimeString(PHP_Timer::stop()));
}
}
示例3: localizeFilter
public function localizeFilter(\DateTime $dateTime, string $format = null)
{
$carbon = Carbon::createFromTimestampUTC($dateTime->getTimestamp());
$carbon->setTimezone(new \DateTimeZone('Europe/Amsterdam'));
setlocale(LC_ALL, 'nl_NL');
$carbon->setTimezone(new \DateTimeZone('Europe/Amsterdam'));
return $carbon->formatLocalized($format);
}
示例4: farFuture
public function farFuture($years)
{
if ($years < 2) {
throw new \InvalidArgumentException('farFuture() requires $year argument to be at least 2 years or more.');
}
$upper = strtotime('+' . ($years + 1) . ' years');
$lower = strtotime('+' . ($years - 1) . ' years');
return Carbon::createFromTimestampUTC($this->generator->math->between($lower, $upper));
}
示例5: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$files = Storage::disk('s3')->files('backups');
foreach ($files as $file) {
$modified = Storage::disk('s3')->lastModified($file);
$date = Carbon\Carbon::createFromTimestampUTC($modified);
if ($date < Carbon\Carbon::now()->subMonth(1)) {
Storage::disk('s3')->delete($file);
$this->info("Deleted " . $file);
}
}
}
示例6: testGetScheduledMeetings
public function testGetScheduledMeetings()
{
$meetings = $this->meetingService->getScheduledMeetings();
$this->assertNotEmpty($meetings);
$actualMeeting = $meetings[0];
$this->assertInstanceOf('\\kenobi883\\GoToMeeting\\Models\\Meeting', $actualMeeting);
$this->assertAttributeNotEmpty('meetingId', $actualMeeting);
$this->assertAttributeInstanceOf('\\DateTime', 'startTime', $actualMeeting);
$startTime = Carbon::createFromTimestampUTC($actualMeeting->getStartTime()->getTimestamp());
$this->assertTrue($startTime->between(Carbon::now('UTC')->subYear(), Carbon::now('UTC')->addYear()));
$this->assertAttributeInstanceOf('\\DateTime', 'endTime', $actualMeeting);
$endTime = Carbon::createFromTimestampUTC($actualMeeting->getEndTime()->getTimestamp());
$this->assertTrue($endTime->between(Carbon::now('UTC')->subYear(), Carbon::now('UTC')->addYear()));
}
示例7: processCertificate
public function processCertificate($certificateInfo)
{
if (!empty($certificateInfo['subject']) && !empty($certificateInfo['subject']['CN'])) {
$this->certificateDomain = $certificateInfo['subject']['CN'];
}
if (!empty($certificateInfo['validTo_time_t'])) {
$validTo = Carbon::createFromTimestampUTC($certificateInfo['validTo_time_t']);
$this->certificateExpiration = $validTo->toDateString();
$this->certificateDaysUntilExpiration = -$validTo->diffInDays(Carbon::now(), false);
}
if (!empty($certificateInfo['extensions']) && !empty($certificateInfo['extensions']['subjectAltName'])) {
$this->certificateAdditionalDomains = [];
$domains = explode(', ', $certificateInfo['extensions']['subjectAltName']);
foreach ($domains as $domain) {
$this->certificateAdditionalDomains[] = str_replace('DNS:', '', $domain);
}
}
}
示例8: convert
public function convert($datetime)
{
if (is_array($datetime)) {
if (count($datetime) <= 6) {
$datetime = array_pad($datetime, 6, null);
}
$datetime[] = $this->getOption('timezone');
$method = new ReflectionMethod('Carbon\\Carbon', 'create');
return $method->invokeArgs(null, $datetime);
} elseif ('timestamp' == $this->getOption('format')) {
return Carbon::createFromTimestamp($datetime, $this->getOption('timezone'));
} elseif ('utc_timestamp' == $this->getOption('format')) {
return Carbon::createFromTimestampUTC($datetime, $this->getOption('timezone'));
} elseif ($format = $this->getOption('format')) {
return Carbon::createFromFormat($format, $datetime, $this->getOption('timezone'));
}
return new Carbon($datetime, $this->getOption('timezone'));
}
示例9: recordSubscription
/**
* @todo refactor all these if statements
*
* @param LaravelMixpanel $mixPanel
* @param $transaction
* @param $user
* @param array $originalValues
*/
private function recordSubscription(LaravelMixpanel $mixPanel, $transaction, $user, array $originalValues = [])
{
$planStatus = array_key_exists('status', $transaction) ? $transaction['status'] : null;
$planName = isset($transaction['plan']['name']) ? $transaction['plan']['name'] : null;
$planStart = array_key_exists('start', $transaction) ? $transaction['start'] : null;
$planAmount = isset($transaction['plan']['amount']) ? $transaction['plan']['amount'] : null;
$oldPlanName = isset($originalValues['plan']['name']) ? $originalValues['plan']['name'] : null;
$oldPlanAmount = isset($originalValues['plan']['amount']) ? $originalValues['plan']['amount'] : null;
if ($planStatus === 'canceled') {
$mixPanel->people->set($user->id, ['Subscription' => 'None', 'Churned' => Carbon::now('UTC')->format('Y-m-d\\Th:i:s'), 'Plan When Churned' => $planName, 'Paid Lifetime' => Carbon::createFromTimestampUTC($planStart)->diffInDays(Carbon::now('UTC')) . ' days']);
$mixPanel->track('Subscription', ['Status' => 'Canceled', 'Upgraded' => false]);
$mixPanel->track('Churn! :-(');
}
if (count($originalValues)) {
if ($planAmount && $oldPlanAmount) {
if ($planAmount < $oldPlanAmount) {
$mixPanel->people->set($user->id, ['Subscription' => $planName, 'Churned' => Carbon::now('UTC')->format('Y-m-d\\Th:i:s'), 'Plan When Churned' => $oldPlanName]);
$mixPanel->track('Subscription', ['Upgraded' => false, 'FromPlan' => $oldPlanName, 'ToPlan' => $planName]);
$mixPanel->track('Churn! :-(');
}
if ($planAmount > $oldPlanAmount) {
$mixPanel->people->set($user->id, ['Subscription' => $planName]);
$mixPanel->track('Subscription', ['Upgraded' => true, 'FromPlan' => $oldPlanName, 'ToPlan' => $planName]);
$mixPanel->track('Unchurn! :-)');
}
} else {
if ($planStatus === 'trialing' && !$oldPlanName) {
$mixPanel->people->set($user->id, ['Subscription' => $planName]);
$mixPanel->track('Subscription', ['Upgraded' => true, 'FromPlan' => 'Trial', 'ToPlan' => $planName]);
$mixPanel->track('Unchurn! :-)');
}
}
} else {
if ($planStatus === 'active') {
$mixPanel->people->set($user->id, ['Subscription' => $planName]);
$mixPanel->track('Subscription', ['Status' => 'Created']);
}
if ($planStatus === 'trialing') {
$mixPanel->people->set($user->id, ['Subscription' => 'Trial']);
$mixPanel->track('Subscription', ['Status' => 'Trial']);
}
}
}
示例10: function
<?php
echo GridView::widget(['id' => 'template-category-grid', 'dataProvider' => $dataProvider, 'resizableColumns' => false, 'pjax' => false, 'export' => false, 'responsive' => true, 'bordered' => false, 'striped' => true, 'panelTemplate' => '<div class="panel {type}">
{panelHeading}
{panelBefore}
{items}
<div style="text-align: center">{pager}</div>
</div>', 'panel' => ['type' => GridView::TYPE_INFO, 'heading' => Yii::t('app', 'Templates') . ' <small class="panel-subtitle hidden-xs">' . Yii::t('app', 'By Categories') . '</small>', 'footer' => false, 'before' => ActionBar::widget(['grid' => 'template-category-grid', 'templates' => ['{create}' => ['class' => 'col-xs-6 col-md-8'], '{bulk-actions}' => ['class' => 'col-xs-6 col-md-2 col-md-offset-2']], 'bulkActionsItems' => [Yii::t('app', 'General') => ['general-delete' => Yii::t('app', 'Delete')]], 'bulkActionsOptions' => ['options' => ['general-delete' => ['url' => Url::toRoute('delete-multiple'), 'data-confirm' => Yii::t('app', 'Are you sure you want to delete these template categories? All data related to each item will be deleted. This action cannot be undone.')]], 'class' => 'form-control'], 'elements' => ['create' => Html::a('<span class="glyphicon glyphicon-plus"></span> ' . Yii::t('app', 'Create Category'), ['create'], ['class' => 'btn btn-primary']) . ' ' . Html::a(Yii::t('app', 'Need to extend the app functionality?'), ['/addons'], ['data-toggle' => 'tooltip', 'data-placement' => 'top', 'title' => Yii::t('app', 'With our add-ons you can add great features and integrations to your forms. Try them now!'), 'class' => 'text hidden-xs hidden-sm'])], 'class' => 'form-control'])], 'toolbar' => false, 'columns' => [['class' => '\\kartik\\grid\\CheckboxColumn', 'headerOptions' => ['class' => 'kartik-sheet-style'], 'rowSelectedClass' => GridView::TYPE_WARNING], ['attribute' => 'name', 'format' => 'raw', 'value' => function ($model) {
return Html::a(Html::encode($model->name), ['templates/category', 'id' => $model->id]);
}], ['attribute' => 'description', 'value' => function ($model) {
if (isset($model->description)) {
return StringHelper::truncateWords(Html::encode($model->description), 15);
}
return null;
}], ['attribute' => 'updated_at', 'value' => function ($model) {
if (isset($model->updated_at)) {
return Carbon::createFromTimestampUTC($model->updated_at)->diffForHumans();
}
return null;
}, 'label' => Yii::t('app', 'Last updated')], ['class' => 'kartik\\grid\\ActionColumn', 'dropdown' => true, 'dropdownButton' => ['class' => 'btn btn-primary'], 'dropdownOptions' => ['class' => 'pull-right'], 'buttons' => ['view' => function ($url) {
$options = array_merge(['title' => Yii::t('app', 'View'), 'aria-label' => Yii::t('app', 'View'), 'data-pjax' => '0'], []);
return '<li>' . Html::a('<span class="glyphicon glyphicon-eye-open"></span> ' . Yii::t('app', 'View Record'), $url, $options) . '</li>';
}, 'update' => function ($url) {
$options = array_merge(['title' => Yii::t('app', 'Update'), 'aria-label' => Yii::t('app', 'Update'), 'data-pjax' => '0'], []);
return '<li>' . Html::a('<span class="glyphicon glyphicon-pencil"></span> ' . Yii::t('app', 'Update'), $url, $options) . '</li>';
}, 'delete' => function ($url) {
$options = array_merge(['title' => Yii::t('app', 'Delete'), 'aria-label' => Yii::t('app', 'Delete'), 'data-confirm' => Yii::t('app', 'Are you sure you want to delete this template category?
All data related to this item will be deleted. This action cannot be undone.'), 'data-method' => 'post', 'data-pjax' => '0'], []);
return '<li>' . Html::a('<span class="glyphicon glyphicon-bin"></span> ' . Yii::t('app', 'Delete'), $url, $options) . '</li>';
}]]]]);
?>
示例11: expirationDate
public function expirationDate() : Carbon
{
return Carbon::createFromTimestampUTC($this->rawCertificateFields['validTo_time_t']);
}
示例12: isset
$this->params['breadcrumbs'][] = $this->title;
Carbon::setLocale(substr(Yii::$app->language, 0, 2));
// eg. en-US to en
?>
<div class="template-category-view box box-big box-light">
<div class="pull-right" style="margin-top: -5px">
<?php
echo Html::a('<span class="glyphicon glyphicon-pencil"></span> ', ['update', 'id' => $model->id], ['title' => Yii::t('app', 'Update Template'), 'class' => 'btn btn-sm btn-info']);
?>
<?php
echo Html::a('<span class="glyphicon glyphicon-bin"></span> ', ['delete', 'id' => $model->id], ['title' => Yii::t('app', 'Delete Template'), 'class' => 'btn btn-sm btn-danger', 'data' => ['confirm' => Yii::t('app', 'Are you sure you want to delete this template category? All data related to this item will be deleted. This action cannot be undone.'), 'method' => 'post']]);
?>
</div>
<div class="box-header">
<h3 class="box-title"><?php
echo Yii::t('app', 'Template Category');
?>
<span class="box-subtitle"><?php
echo Html::encode($this->title);
?>
</span>
</h3>
</div>
<?php
echo DetailView::widget(['model' => $model, 'condensed' => false, 'hover' => true, 'mode' => DetailView::MODE_VIEW, 'enableEditMode' => false, 'hideIfEmpty' => true, 'options' => ['class' => 'kv-view-mode'], 'attributes' => ['id', 'name', 'description', ['attribute' => 'created_at', 'value' => isset($model->created_at) ? Carbon::createFromTimestampUTC($model->created_at)->diffForHumans() : null, 'label' => Yii::t('app', 'Created')], ['attribute' => 'updated_at', 'value' => isset($model->updated_at) ? Carbon::createFromTimestampUTC($model->updated_at)->diffForHumans() : null, 'label' => Yii::t('app', 'Last updated')]]]);
?>
</div>
示例13:
?>
</div>
<div class="list-group">
<?php
foreach ($lastUpdatedForms as $form) {
?>
<a href="<?php
echo Url::to(['form/view', 'id' => $form['id']]);
?>
"
class="list-group-item"><?php
echo Html::encode($form['name']);
?>
<span class="label label-info">
<?php
echo Carbon::createFromTimestampUTC($form['updated_at'])->diffForHumans();
?>
</span>
</a>
<?php
}
?>
<?php
if (count($lastUpdatedForms) == 0) {
?>
<div class="list-group-item"><?php
echo Yii::t('app', 'No data');
?>
</div>
<?php
}
示例14: convert
/**
* @param $date
* @return static
*/
public static function convert($date)
{
$date2 = (int) ($date / 1000);
$date_string = Carbon::createFromTimestampUTC($date2)->toDayDateTimeString();
return $date_string;
}
示例15: activeHours
public function activeHours()
{
$hours = array_fill(0, 24, 0);
foreach ($this->getSubmissions() as $submission) {
$time = Carbon::createFromTimestampUTC($submission->data->created_utc);
// $time->timezone = new DateTimeZone('America/Vancouver');
$hour = $time->hour;
$hours[$hour]++;
}
return $hours;
}