当前位置: 首页>>代码示例>>PHP>>正文


PHP Carbon::instance方法代码示例

本文整理汇总了PHP中Carbon::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Carbon::instance方法的具体用法?PHP Carbon::instance怎么用?PHP Carbon::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Carbon的用法示例。


在下文中一共展示了Carbon::instance方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getMinutes

 /**
  * Calculate the number of minutes with the given duration.
  *
  * @param  \DateTime|int  $duration
  * @return int|null
  */
 protected function getMinutes($duration)
 {
     if ($duration instanceof DateTime) {
         $fromNow = Carbon::now()->diffInMinutes(Carbon::instance($duration), false);
         return $fromNow > 0 ? $fromNow : null;
     }
     return $duration;
 }
开发者ID:barbery,项目名称:laravel-phpredis,代码行数:14,代码来源:Repository.php

示例2: run

 public function run()
 {
     $faker = Faker::create();
     $count = 100;
     $region_ids = Region::lists('region_id');
     foreach (range(1, $count) as $i) {
         Quotation::create(['A76_80' => $faker->randomFloat(6, $min = 19, $max = 24), 'A92' => $faker->randomFloat(6, $min = 19, $max = 24), 'A95' => $faker->randomFloat(6, $min = 19, $max = 24), 'region_id' => $faker->randomElement($region_ids), 'added_on' => Carbon::instance($faker->dateTimeBetween('10.07.2015', '16.07.2015'))->toDateString()]);
     }
 }
开发者ID:beststrelok,项目名称:petrol,代码行数:9,代码来源:QuotationSeeder.php

示例3: diffInDaysFiltered

 /**
  * Get the difference in days using a filter closure
  *
  * @param Closure $callback
  * @param Carbon  $dt
  * @param boolean $abs      Get the absolute of the difference
  *
  * @return int
  */
 public function diffInDaysFiltered(Closure $callback, Carbon $dt = null, $abs = true)
 {
     $start = $this;
     $end = $dt === null ? static::now($this->tz) : $dt;
     $inverse = false;
     if ($end < $start) {
         $start = $end;
         $end = $this;
         $inverse = true;
     }
     $period = new DatePeriod($start, new DateInterval('P1D'), $end);
     $days = array_filter(iterator_to_array($period), function (DateTime $date) use($callback) {
         return call_user_func($callback, Carbon::instance($date));
     });
     $diff = count($days);
     return $inverse && !$abs ? -$diff : $diff;
 }
开发者ID:nomantufail,项目名称:virik_updating,代码行数:26,代码来源:Carbon.php

示例4: getTrialEndDate

 /**
  * getTrialEndDate
  * --------------------------------------------------
  * Returns the trial period ending date
  * @return (date) ($trialEndDate) The ending date
  * --------------------------------------------------
  */
 public function getTrialEndDate()
 {
     /* Return the date */
     return Carbon::instance($this->created_at)->addDays(SiteConstants::getTrialPeriodInDays());
 }
开发者ID:neraunzaran,项目名称:fruit-dashboard,代码行数:12,代码来源:User.php

示例5: SetupClientDetailsFromCache

 public function SetupClientDetailsFromCache(&$client)
 {
     if (!isset($client->TDates)) {
         $client->TDates = new stdClass();
     }
     $CreatedOn = new DateTime($client->CreatedOn, new DateTimeZone('America/Los_Angeles'));
     $client->TDates->CreatedOn = $CreatedOn->format('m/d/Y h:ia');
     $UpdatedOn = new DateTime($client->UpdatedOn, new DateTimeZone('America/Los_Angeles'));
     $UpdatedOn->setTimezone(new DateTimeZone('America/New_York'));
     $client->TDates->UpdatedOn = $UpdatedOn->format('m/d/Y h:ia T');
     $fromNow = Carbon::instance($UpdatedOn)->diffInMinutes();
     $client->TDates->UpdatedMinutesAgo = $fromNow;
 }
开发者ID:jordone,项目名称:diyonline,代码行数:13,代码来源:leadtracapi.php

示例6:

    </div>
    <div class="col col-sm-3">
        
    </div>
    <div class="col col-sm-3">
        @if($post->last_editor_user_id != "")
        <div class="well user-info-box">
            <span>
                <a href="/user/{{ $post->user_id }}">
                    {{ $post->owner_display_name }}
                </a> - {{ $post->user->reputation }}
            </span>
        </div>
        @endif
    </div>
    <div class="col col-sm-3">
        <div class="well user-info-box">
            <p>
                <?php 
$askedDate = Carbon::instance($post->created_at);
?>
                asked {{ $askedDate->toFormattedDateString() }}
            </p>
            <span>
                <a href="/user/{{ $post->user_id }}">
                    {{ $post->owner_display_name }}
                </a> - {{ $post->user->reputation }}
            </span>
        </div>
    </div>
</div>
开发者ID:UnderDogg,项目名称:StackOverflow-Clone,代码行数:31,代码来源:post-actions.blade.php

示例7:

            <?php 
$date = Carbon::instance($post->created_at);
echo $date->diffForHumans(Carbon::now());
?>
        </p>
    </li>
    <li>
        <p>
            <b>Views:</b>
            {{ $post->view_count }}
        </p>
    </li>
    <li>
        <p>
            <b>Active: </b>
            <?php 
$date = Carbon::instance($post->updated_at);
echo $date->diffForHumans(Carbon::now());
?>
        </p>
    </li>
</ul>

<h2>Tags</h2>
@foreach($tags as $t)
<p>
    <a href="/tag/{{ $t->id }}">
        <span class="badge">{{ $t->name }}</span>
    </a>
</p>
@endforeach
开发者ID:UnderDogg,项目名称:StackOverflow-Clone,代码行数:31,代码来源:question.blade.php

示例8: getMinutes

 /**
  * Calculate the number of minutes with the given duration.
  *
  * @param  \DateTime|int  $duration
  * @return int
  */
 protected function getMinutes($duration)
 {
     if ($duration instanceof DateTime) {
         return max(0, Carbon::instance($duration)->diffInMinutes());
     }
     return is_string($duration) ? intval($duration) : $duration;
 }
开发者ID:astronautyan,项目名称:O2OMobile_PHP,代码行数:13,代码来源:TaggedCache.php

示例9: pilots

 /**
  * Processes the flights in the datafeed, both new and existing
  * in the database. As well as any flights in the database that
  * have not arrived yet but are missing from the datafeed.
  *
  * @return void
  */
 protected function pilots()
 {
     $this->elevations();
     // First we will select all flights from the database which
     // have not yet been marked as arrived and are not missing.
     $database = Flight::where('state', '!=', '2')->get();
     $insert = array();
     $update = array();
     $default = array('route' => '', 'remarks' => '', 'altitude' => '', 'speed' => '', 'flighttype' => 'I', 'last_lat' => '0', 'last_lon' => '0', 'last_altitude' => '0', 'last_speed' => '0', 'last_heading' => '0', 'missing' => '0', 'startdate' => date('Y-m-d'), 'revision' => '0', 'callsign' => '', 'callsign_type' => '0', 'airline_id' => null, 'vatsim_id' => '', 'aircraft_code' => '', 'aircraft_id' => null, 'departure_id' => '', 'arrival_id' => '', 'state' => '4', 'departure_time' => null, 'arrival_time' => null, 'departure_country_id' => '', 'arrival_country_id' => '', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now());
     foreach ($this->pilots as $entry) {
         try {
             // Find the flight in the data we fetched using the callsign
             // and vatsim id of the pilot. If the flight does not exist
             // in the database we will create a new one.
             $flightKey = null;
             $flight = $database->first(function ($key, $flight) use($entry, &$flightKey) {
                 if (str_replace('-', '', $flight->callsign) == str_replace('-', '', $entry['callsign']) && $flight->vatsim_id == $entry['cid']) {
                     $flightKey = $key;
                     return true;
                 }
                 return false;
             }, new Flight());
             // Some data will have to be refreshed with every update of
             // the datafeed. Pilots have the ability to update the route,
             // remarks, altitude and speed at all times using a new flight plan.
             $flight->route = $entry['planned_route'];
             $flight->remarks = $entry['planned_remarks'];
             $flight->altitude = $entry['planned_altitude'];
             $flight->speed = $entry['planned_tascruise'];
             $flight->flighttype = $entry['planned_flighttype'];
             // Update last known coordinates
             $flight->last_lat = $entry['latitude'];
             $flight->last_lon = $entry['longitude'];
             $flight->last_altitude = $entry['altitude'];
             $flight->last_speed = $entry['groundspeed'];
             $flight->last_heading = $entry['heading'];
             // We also need to ensure that the flight is not marked as missing,
             // now that we have a record of the flight again.
             $flight->missing = 0;
             // If the flight does not exist we need to load the basic
             // data, such as date, pilot, callsign, aircraft, etc.
             if (!$flight->exists) {
                 $flight->startdate = Carbon::createFromFormat('YmdHis', $entry['time_logon'], 'UTC')->toDateString();
                 $flight->revision = $entry['planned_revision'];
                 $callsign = $this->callsign($entry['callsign']);
                 $flight->callsign = $callsign['callsign'];
                 $flight->callsign_type = $callsign['callsign_type'];
                 $flight->airline_id = $callsign['airline_id'];
                 $flight->vatsim_id = $entry['cid'];
                 $flight->aircraft_code = $entry['planned_aircraft'];
                 $flight->aircraft_id = $this->aircraft($entry['planned_aircraft']);
                 $flight->departure_id = $entry['planned_depairport'];
                 $flight->arrival_id = $entry['planned_destairport'];
                 $flight->state = 4;
                 $this->vatsimUser($entry['cid']);
                 try {
                     if ($entry['planned_deptime'] > 0 && $entry['planned_deptime'] < 2359 && !empty($entry['planned_deptime'])) {
                         $date = $flight->startdate;
                         list($hour, $minute) = str_split(str_pad($entry['planned_deptime'], 4, '0', STR_PAD_LEFT), 2);
                         $flight->departure_time = Carbon::createFromFormat('Y-m-d H:i', $date . ' ' . $hour . ':' . $minute, 'UTC');
                     }
                 } catch (InvalidArgumentException $e) {
                     Log::warning($entry['planned_deptime']);
                     Log::warning($e);
                 }
             } else {
                 // Update distance
                 try {
                     $flight->distance += acos(sin(deg2rad($flight->getOriginal('last_lat'))) * sin(deg2rad($entry['latitude'])) + cos(deg2rad($flight->getOriginal('last_lat'))) * cos(deg2rad($entry['latitude'])) * cos(deg2rad($flight->getOriginal('last_lon')) - deg2rad($entry['longitude']))) * 6371;
                 } catch (ErrorException $e) {
                     Log::debug($e);
                 }
                 // Add the position report
                 $this->positionReport($entry, $flight->id);
                 // Only allow the departure airport/time to be updated if the
                 // current state is preparing(4) or departing(0). If done after
                 // that it's technically too late since they have already departed.
                 if (in_array($flight->state, [0, 4]) && $entry['planned_deptime'] > 0 && $entry['planned_deptime'] < 2359 && !empty($entry['planned_deptime'])) {
                     $date = $flight->startdate;
                     list($hour, $minute) = str_split(str_pad($entry['planned_deptime'], 4, '0', STR_PAD_LEFT), 2);
                     $flight->departure_time = Carbon::createFromFormat('Y-m-d H:i', $date . ' ' . $hour . ':' . $minute, 'UTC');
                 }
                 $flight->departure_id = $entry['planned_depairport'];
                 $flight->arrival_id = $entry['planned_destairport'];
             }
             // Update the arrival time to always be the planned flight time
             // from the departure time.
             if (!is_null($flight->departure_time)) {
                 $flight->arrival_time = Carbon::instance($flight->departure_time)->addHours($entry['planned_hrsenroute'])->addMinutes($entry['planned_minenroute']);
             } else {
                 $flight->arrival_time = null;
             }
             // Workflow processes
//.........这里部分代码省略.........
开发者ID:T-SummerStudent,项目名称:new,代码行数:101,代码来源:VatawareUpdateCommand.php

示例10: deletedAt

 /**
  * @return \Carbon\Carbon
  */
 public function deletedAt()
 {
     return Carbon::instance($this->deletedAt->date());
 }
开发者ID:proai,项目名称:laravel-datamapper,代码行数:7,代码来源:SoftDeletes.php


注:本文中的Carbon::instance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。