本文整理汇总了PHP中Carbon\Carbon::createFromTimestamp方法的典型用法代码示例。如果您正苦于以下问题:PHP Carbon::createFromTimestamp方法的具体用法?PHP Carbon::createFromTimestamp怎么用?PHP Carbon::createFromTimestamp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carbon\Carbon
的用法示例。
在下文中一共展示了Carbon::createFromTimestamp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* @param $string
* @param null $path
* @return string
*/
public function parse($string, $path = null)
{
$headers = [];
$parts = preg_split('/[\\n]*[-]{3}[\\n]/', $string, 3);
if (count($parts) == 3) {
$string = $parts[0] . "\n" . $parts[2];
$headers = $this->yaml->parse($parts[1]);
}
$file = new SplFileInfo($path, '', '');
$date = Carbon::createFromTimestamp($file->getMTime());
$dateFormat = config('fizl-pages::date_format', 'm/d/Y g:ia');
$headers['date_modified'] = $date->toDateTimeString();
if (isset($headers['date'])) {
try {
$headers['date'] = Carbon::createFromFormat($dateFormat, $headers['date'])->toDateTimeString();
} catch (\InvalidArgumentException $e) {
$headers['date'] = $headers['date_modified'];
//dd($e->getMessage());
}
} else {
$headers['date'] = $headers['date_modified'];
}
$this->execute(new PushHeadersIntoCollectionCommand($headers, $this->headers));
$viewPath = PageHelper::filePathToViewPath($path);
$cacheKey = "{$viewPath}.headers";
$this->cache->put($cacheKey, $headers);
return $string;
}
示例2: whole
public function whole()
{
$before = Input::get('period');
if (!empty($before)) {
$before = Carbon::createFromTimestamp(strtotime('tomorrow') - (int) $before * 24 * 60 * 60)->toDateTimeString();
}
$totalOrders = $this->orderRepo->countAll($before);
$totalCustomers = $this->userRepo->countAllCustomers($before);
$totalLeads = $this->leadRepo->countAll($before);
$totalSystemUsers = $this->userRepo->countAllUsers($before);
$totalUndefinedLeads = $this->leadRepo->countWithQuery($before, ['status' => 0]);
$totalSuccessfulLeads = $this->leadRepo->countWithQuery($before, ['status' => 1]);
$totalUnsuccessfulLeads = $this->leadRepo->countWithQuery($before, ['status' => -1]);
$totalPendingLeads = $this->leadRepo->countWithQuery($before, ['status' => 2]);
$generalPanelOrders = $this->orderRepo->countWithQuery($before, ['panel_type' => 0]);
$experimentalPanels = $this->orderRepo->countWithQuery($before, ['panel_type' => 2]);
$freePanels = $this->orderRepo->countWithQuery($before, ['panel_type' => 1]);
$couponPanels = $this->orderRepo->countWithQuery($before, ['panel_type' => 3]);
$panelLess = $this->orderRepo->countWithQuery($before, ['panel_type' => 4]);
$hasPanels = $this->orderRepo->countWithQuery($before, ['panel_type' => 5]);
$completedOrders = $this->orderRepo->countWithQuery($before, ['completed' => 1]);
$fromLeadCustomers = $this->userRepo->countWithLead($before);
$totalPanelPrice = $this->orderRepo->sumPanelPrice($before);
return $this->view('admin.pages.stat.whole', compact('totalOrders', 'totalLeads', 'totalSystemUsers', 'totalCustomers', 'totalUndefinedLeads', 'totalSuccessfulLeads', 'totalPendingLeads', 'totalUnsuccessfulLeads', 'generalPanelOrders', 'experimentalPanels', 'freePanels', 'couponPanels', 'panelLess', 'hasPanels', 'completedOrders', 'fromLeadCustomers', 'totalPanelPrice'));
}
示例3: __construct
/**
* Series constructor.
*
* @param $data
*/
public function __construct($data)
{
$this->id = (int) $data->id;
$this->language = (string) $data->Language;
$this->name = (string) $data->SeriesName;
$this->banner = (string) $data->banner;
$this->overview = (string) $data->Overview;
$this->firstAired = (string) $data->FirstAired !== '' ? Carbon::createFromFormat('Y-m-d', (string) $data->FirstAired)->toDateString() : null;
$this->imdbId = (string) $data->IMDB_ID;
if (isset($data->Actors)) {
$this->actors = (array) TVDB::removeEmptyIndexes(explode('|', (string) $data->Actors));
}
$this->airsDayOfWeek = (string) $data->Airs_DayOfWeek;
$this->airsTime = (string) $data->Airs_Time;
$this->contentRating = (string) $data->ContentRating;
if (isset($data->Genre)) {
$this->genres = (array) TVDB::removeEmptyIndexes(explode('|', (string) $data->Genre));
}
$this->network = (string) $data->Network;
$this->rating = (double) $data->Rating;
$this->ratingCount = (int) $data->RatingCount;
$this->runtime = (int) $data->Runtime;
$this->status = (string) $data->Status;
if (isset($data->added)) {
// $this->added = Carbon::createFromFormat('Y-m-d H:i:s', (string)$data->added)->toDateTimeString();
}
$this->fanArt = (string) $data->fanart;
$this->lastUpdated = Carbon::createFromTimestamp((int) $data->lastupdated)->toDateTimeString();
$this->poster = (string) $data->poster;
$this->zap2itId = (string) $data->zap2it_id;
if (isset($data->AliasNames)) {
$this->aliasNames = (array) TVDB::removeEmptyIndexes(explode('|', (string) $data->AliasNames));
}
}
示例4: normalize
/**
* @param $postData
* @return mixed
*/
public static function normalize(&$postData)
{
$postId = sprintf('%d_%d', $postData['from_id'], $postData['id']);
$post = PostModel::firstOrNew(['external_id' => $postId]);
self::$__count_imports_posts++;
if (!$post->id) {
self::$__count_imports_new_posts++;
}
$text = '';
if ($postData['post_type'] == 'copy') {
$text = isset($postData['copy_text']) && !empty($postData['copy_text']) ? $postData['copy_text'] : '';
}
$text .= !empty($text) && !empty($postData['text']) ? '<br>' : '';
$text .= !empty($postData['text']) ? $postData['text'] : '';
$post->date = Carbon::createFromTimestamp($postData['date']);
$post->text = $text;
$post->save();
// dump($text, $post->text);
if (isset($postData['attachments'])) {
$attachments = self::attachmentsPost($postData['attachments']);
if (sizeof($attachments) > 0) {
$post->attachments()->sync($attachments, false);
}
}
return $post;
}
示例5: it_formats_given_datetime_and_carbon_instance
/** @test */
public function it_formats_given_datetime_and_carbon_instance()
{
$date = (new DateTime())->setTimestamp(1458779168);
$this->assertEquals('Mar 24 2016', $this->helper->dateFormat($date));
$date = Carbon::createFromTimestamp(1458779168);
$this->assertEquals('Mar 24 2016', $this->helper->dateFormat($date));
}
示例6: testConvert
/**
* @covers ::convert
*/
public function testConvert()
{
$test1 = Converter::convert(Calends::create(0, 'unix'));
$this->assertEquals(['start' => Carbon::createFromTimestamp(0), 'duration' => \Carbon\CarbonInterval::seconds(0), 'end' => Carbon::createFromTimestamp(0)], $test1);
$test2 = Converter::convert(Calends::create(['start' => 0, 'end' => 86400], 'unix'));
$this->assertEquals(['start' => Carbon::createFromTimestamp(0), 'duration' => \Carbon\CarbonInterval::seconds(86400), 'end' => Carbon::createFromTimestamp(86400)], $test2);
}
示例7: getSelfInstagrams
public function getSelfInstagrams()
{
$url = 'https://api.instagram.com/v1/users/self/media/recent/?access_token=' . env('INSTAGRAM_ACCESS_TOKEN');
$content = file_get_contents($url);
$json = json_decode($content, true);
foreach ($json['data'] as $images) {
$imgUrl = $images['images']['standard_resolution']['url'];
$description = $images['caption']['text'];
$datetime_posted = $images['caption']['created_time'];
$datetime_posted = Carbon::createFromTimestamp($datetime_posted)->toDateTimeString();
$username = $images['caption']['from']['username'];
$profilePic = $images['caption']['from']['profile_picture'];
$link = $images['link'];
if (SocialMedia::where('imgUrl', $imgUrl)->exists()) {
echo "This post already exists";
} else {
$insta = new SocialMedia();
$insta->username = $username;
$insta->profile_pic_url = $profilePic;
$insta->tweet = 'N/A';
$insta->caption = $description;
$insta->imgUrl = $imgUrl;
$insta->message = 'N/A';
$insta->source = 'Admin-Insta';
$insta->link = $link;
$insta->resize = 'fit';
$insta->approved = 'Approved';
$insta->approver_id = -1;
$insta->datetime_posted = $datetime_posted;
$insta->save();
echo "Saved!";
}
}
}
示例8: adminIndexAll
public function adminIndexAll()
{
$posts = Post::orderBy('updated_at', 'desc')->paginate();
return View::make('admin.dicts.list', ['columns' => ['ID', 'Пользователь', 'Текст', 'Рубрика', 'Лайки', 'Комментарии', 'Время', '', ''], 'data' => $posts->transform(function ($post) {
return ['id' => $post->id, 'user' => link_to("admin/users{$post->user_id}", $post->user->name), 'text' => link_to("admin/posts/{$post->id}/edit", $post->text), 'category' => link_to("/admin/categories/{$post->category_id}/edit", $post->category->title), 'likes' => link_to("admin/posts/{$post->id}/likes", $post->likes->count()), 'comments' => link_to("admin/posts/{$post->id}/comments", $post->comments->count()), 'time' => Carbon::createFromTimestamp($post->created_at), 'edit' => link_to("/admin/posts/{$post->id}/edit", 'редактировать'), 'delete' => link_to("/admin/posts/{$post->id}/delete", 'удалить')];
}), 'actions' => [['link' => 'admin/posts/delete', 'text' => 'Удалить выбранное']], 'links' => $posts->links(), 'title' => 'Посты']);
}
示例9: cleanValue
public function cleanValue($value)
{
switch ($this->typeName) {
case "number":
return floatval($value);
break;
case "string":
return "" . $value;
break;
case "datetime":
$timezone = isset($this->options['timezone']) ? $this->options['timezone'] : "UTC";
// Assuming that the value that client has given is in UTC
$timeObject = Carbon::createFromTimestamp(intval($value), "UTC");
// Now convert this into the target timezone
$timeObject->setTimezone($timezone);
return $timeObject;
break;
case "date":
$date = date_create($value);
$date = date_format($date, 'm-d-Y');
return $date;
break;
default:
throw new \Exception("Unknown type {$this->typeName}");
}
}
示例10: getThread
/**
* Returns a thread and its replies to the client.
*
* @var Board $board
* @var integer|null $thread
* @return Response
*/
public function getThread(Request $request, Board $board, $thread)
{
if (is_null($thread)) {
return abort(404);
}
$input = $request->only('updatesOnly', 'updateHtml', 'updatedSince');
if (isset($input['updatesOnly'])) {
$updatedSince = Carbon::createFromTimestamp($request->input('updatedSince', 0));
$posts = Post::where('posts.board_uri', $board->board_uri)->withEverything()->where(function ($query) use($thread) {
$query->where('posts.reply_to_board_id', $thread);
$query->orWhere('posts.board_id', $thread);
})->where(function ($query) use($updatedSince) {
$query->where('posts.updated_at', '>=', $updatedSince);
$query->orWhere('posts.deleted_at', '>=', $updatedSince);
})->withTrashed()->orderBy('posts.created_at', 'asc')->get();
if (isset($input['updateHtml'])) {
foreach ($posts as $post) {
$appends = $post->getAppends();
$appends[] = "html";
$post->setAppends($appends);
}
}
return $posts;
} else {
// Pull the thread.
$thread = $board->getThreadByBoardId($thread);
if (!$thread) {
return abort(404);
}
}
return $thread;
}
示例11: getOldTime
/**
* @return Carbon
*/
protected function getOldTime()
{
if (!isset($this->oldTime)) {
$this->oldTime = Carbon::createFromTimestamp(Setting::get('old-data'));
}
return $this->oldTime;
}
示例12: scopeReporte
public function scopeReporte($query, $arre)
{
//05/02/2016
//26/09/2016
// dd(\Carbon\Carbon::createFromFormat('d/m/Y',$arre['aprobado']['desde']));
if ($arre['Rdesde'] != "" && $arre['Rhasta'] != "") {
$desde = \Carbon\Carbon::createFromTimestamp($arre['Rdesde'])->toDateTimeString();
$hasta = \Carbon\Carbon::createFromFormat('d/m/Y', $arre['Rhasta']);
echo "<pre>";
var_dump($hasta->date);
exit;
$query->whereBetween('created_at', [$desde, $hasta]);
/* $query->join('recepcion','recepcion.id','=','solicitudes.id_trecepcion')
->where('recepcion.id',7);*/
}
if ($arre['aprobado']['desde'] != "" && $arre['aprobado']['hasta'] != "") {
$desde1 = \Carbon\Carbon::createFromFormat('d/m/Y', $arre['aprobado']['desde']);
$hasta2 = \Carbon\Carbon::createFromFormat('d/m/Y', $arre['aprobado']['hasta']);
$date = \Carbon\Carbon::createFromFormat('d/m/Y', '26/01/2016');
//$hasta2 = \Carbon\Carbon::parse($arre['aprobado']['hasta'])->toDateTimeString();
// dd($desde1,$hasta2);
// dd($date);
$nem = \App\Models\Solicitudes::whereBetween('created_at', ['2016-01-26 00:00:00', '2016-01-26 00:00:00'])->get();
dd($nem);
$query->join('usuarios_solicitudes', 'usuarios_solicitudes.id_solicitud', '=', 'solicitudes.id')->where('solicitudes.estatus', 3);
// ->whereBetween('usuarios_solicitudes.fecha_registro', [$desde1, $hasta2]);
}
}
示例13: getCost
public function getCost(Request $request)
{
$credentials = new Aws\Credentials\Credentials(env('AWS_KEY'), env('AWS_SECRET'));
$client = Ec2Client::factory(array('credentials' => $credentials, 'version' => 'latest', 'region' => $request->input('region')));
$terminate = Carbon::parse($request->input('terminateTime'));
$terminateTime = Carbon::parse($request->input('terminateTime'));
$terminate->minute = 00;
$terminate->second = 00;
$terminate->addHour();
$launch = Carbon::parse($request->input('launchTime'));
$launchTime = Carbon::parse($request->input('launchTime'));
$launch->minute = 00;
$launch->second = 00;
//$client = \AWS::createClient('ec2');
$result = $client->describeSpotPriceHistory(['AvailabilityZone' => $request->input('availabilityZone'), 'DryRun' => false, 'StartTime' => $launch, 'EndTime' => $terminate, 'InstanceTypes' => [$request->input('instanceType')], 'ProductDescriptions' => ['Linux/UNIX']]);
$total_cost = 0.0;
$total_seconds = $launch->diffInSeconds($terminate);
$total_hours = $total_seconds / (60 * 60);
$last_time = $terminate;
$computed_seconds = 0;
foreach ($result['SpotPriceHistory'] as $price) {
$price['SpotPrice'] = floatval($price['SpotPrice']);
$available_seconds = new Carbon($last_time = $price['Timestamp']);
$available_seconds = $available_seconds->diffInSeconds(Carbon::createFromTimestamp(0));
$remaining_seconds = $total_seconds - $computed_seconds;
$used_seconds = min($available_seconds, $remaining_seconds);
$total_cost = $total_cost + $price['SpotPrice'] / (60 * 60) * $used_seconds;
$computed_seconds = $computed_seconds + $used_seconds;
$last_time = $price['Timestamp'];
}
return Response(['TotalCost' => $total_cost, 'PaidHours' => $launch->diffInSeconds($terminate) / (60 * 60), 'ActualHours' => $launchTime->diffInSeconds($terminateTime) / (60 * 60)]);
}
示例14: whereTo
/**
* To criteria
*/
public function whereTo($date = null)
{
if ($date) {
$date = Carbon::createFromTimestamp(strtotime($date));
$this->orm->where('date', '<=', $date->toDateString());
}
}
示例15: __toCarbon
/**
* Return a timestamp as Carbon object.
*
* A slightly modified version of \Illuminate\Database\Eloquent\Model::asDateTime().
*
* @param mixed $value
* @param string|null $format
* @return Carbon
*/
protected function __toCarbon($value, $format = null)
{
// If this value is already a Carbon instance, we shall just return it as is.
// This prevents us having to reinstantiate a Carbon instance when we know
// it already is one, which wouldn't be fulfilled by the DateTime check.
if ($value instanceof Carbon) {
return $value;
}
// If the value is already a DateTime instance, we will just skip the rest of
// these checks since they will be a waste of time, and hinder performance
// when checking the field. We will just return the DateTime right away.
if ($value instanceof DateTime) {
return Carbon::instance($value);
}
// If this value is an integer, we will assume it is a UNIX timestamp's value
// and format a Carbon object from this timestamp. This allows flexibility
// when defining your date fields as they might be UNIX timestamps here.
if (is_numeric($value)) {
return Carbon::createFromTimestamp($value);
}
// If the value is in simply year, month, day format, we will instantiate the
// Carbon instances from that format. Again, this provides for simple date
// fields on the database, while still supporting Carbonized conversion.
if (preg_match('/^(\\d{4})-(\\d{2})-(\\d{2})$/', $value)) {
return Carbon::createFromFormat('Y-m-d', $value)->startOfDay();
}
// Use the $format if one was given.
if (isset($format) && is_string($format)) {
return Carbon::createFromFormat($format, $value);
}
// Finally, we'll let carbon work out the format (watch out for ambiguous days/months).
return Carbon::parse($value);
}