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


PHP Carbon::diff方法代码示例

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


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

示例1: getDateDiff

 public function getDateDiff()
 {
     $created = new Carbon($this->created_at);
     $now = Carbon::now();
     $difference = $created->diff($now)->days < 1 ? 'today' : $created->diffForHumans($now, true);
     if ($difference == 'today') {
         return $difference;
     }
     return $difference . " ago";
     //$cDate->diffInDays() . " days ago";
 }
开发者ID:gazatem,项目名称:dblogger,代码行数:11,代码来源:Log.php

示例2: getProfile

 public function getProfile($userid)
 {
     $user = User::find($userid);
     if (count($user) >= 1) {
         $updated = new Carbon($user->updated_at);
         $now = Carbon::now();
         if ($updated->diff($now)->m < 1) {
             $lastOnline = "Last seen less than a minute ago";
         } elseif ($updated->diff($now)->h < 1) {
             $lastOnline = $updated->diffInMinutes($now) > 1 ? sprintf("Last seen %d minutes ago", $updated->diffInMinutes($now)) : sprintf("Last seen %d minute ago", $updated->diffInMinutes($now));
         } elseif ($updated->diff($now)->d < 1) {
             $lastOnline = $updated->diffInHours($now) > 1 ? sprintf("Last seen %d hours ago", $updated->diffInHours($now)) : sprintf("Last seen %d hour ago", $updated->diffInHours($now));
         } elseif ($updated->diff($now)->d < 7) {
             $lastOnline = $updated->diffInDays($now) > 1 ? sprintf("Last seen %d days ago", $updated->diffInDays($now)) : sprintf("Last seen %d day ago", $updated->diffInDays($now));
         } elseif ($updated->diff($now)->m < 1) {
             $lastOnline = $updated->diffInWeeks($now) > 1 ? sprintf("Last seen %d weeks ago", $updated->diffInWeeks($now)) : sprintf("Last seen %d week ago", $updated->diffInWeeks($now));
         } elseif ($updated->diff($now)->y < 1) {
             $lastOnline = $updated->diffInMonths($now) > 1 ? sprintf("Last seen %d months ago", $updated->diffInMonths($now)) : sprintf("Last seen %d month ago", $updated->diffInMonths($now));
         } else {
             $lastOnline = $updated->diffInYears($now) > 1 ? sprintf("Last seen %d years ago", $updated->diffInYears($now)) : sprintf("Last seen %d year ago", $updated->diffInYears($now));
         }
         return view('dashboard.userProfile', ['user' => $user, 'lastOnline' => $lastOnline]);
     } else {
         return view('dashboard.userProfile');
     }
 }
开发者ID:KarmaLaBelle,项目名称:KaiBanchoo-Web,代码行数:26,代码来源:userProfile.php

示例3: date

 public function date($date)
 {
     $created = new Carbon($date);
     $now = Carbon::now();
     $difference = $created->diff($now)->days < 1 ? 'today' : $created->diffForHumans($now);
     $dates = explode(" ", $difference);
     if (count($dates) > 1) {
         if ($dates[1] == "month" or $dates[1] == "months") {
             if ($dates[0] >= 1) {
                 return true;
             }
         } else {
             return false;
         }
     }
     return false;
 }
开发者ID:juan2ramos,项目名称:credito,代码行数:17,代码来源:UploadUserManager.php

示例4: getView

 public function getView(Pirep $pirep)
 {
     // Calculate some data bits (keep it out of the view)
     $extras = [];
     // Airborne Time
     $takeoff = new Carbon($pirep->departure_time);
     $landing = new Carbon($pirep->landing_time);
     $extras['airborneTime'] = $takeoff->diff($landing);
     // Blocks Time
     $offBlocks = new Carbon($pirep->off_blocks_time);
     $onBlocks = new Carbon($pirep->on_blocks_time);
     $extras['blocksTime'] = $offBlocks->diff($onBlocks);
     // Total Time
     $start = new Carbon($pirep->pirep_start_time);
     $finish = new Carbon($pirep->pirep_end_time);
     $extras['totalTime'] = $start->diff($finish);
     // Planned Route
     $routeService = new Route();
     $extras['routePoints'] = $routeService->getAllPointsForRoute($pirep->booking->route);
     // Format Text Log (ugly, I know!)
     $extras['log'] = str_replace('[', '
     [', $pirep->log);
     // Display the PIREP!
     return view('pireps/single', ['pirep' => $pirep, 'extras' => $extras, 'staffBar' => true]);
 }
开发者ID:aorly,项目名称:vAMSYS,代码行数:25,代码来源:PirepsController.php

示例5: getSinglePirep

    public function getSinglePirep(Pirep $pirep)
    {
        // Do we have access to this PIREP?
        if ($pirep->booking->pilot->id !== PilotRepository::getCurrentPilot()->id) {
            return redirect('/pireps');
        }
        // Calculate some data bits (keep it out of the view)
        $extras = [];
        // Airborne Time
        $takeoff = new Carbon($pirep->departure_time);
        $landing = new Carbon($pirep->landing_time);
        $extras['airborneTime'] = $takeoff->diff($landing);
        // Blocks Time
        $offBlocks = new Carbon($pirep->off_blocks_time);
        $onBlocks = new Carbon($pirep->on_blocks_time);
        $extras['blocksTime'] = $offBlocks->diff($onBlocks);
        // Total Time
        $start = new Carbon($pirep->pirep_start_time);
        $finish = new Carbon($pirep->pirep_end_time);
        $extras['totalTime'] = $start->diff($finish);
        // Planned Route
        $routeService = new Route();
        $extras['routePoints'] = $routeService->getAllPointsForRoute($pirep->booking->route);
        // Format Text Log (ugly, I know!)
        $extras['log'] = str_replace('[', '
[', $pirep->log);
        // Display the PIREP!
        return view('pireps/single', ['pirep' => $pirep, 'extras' => $extras]);
    }
开发者ID:aorly,项目名称:vAMSYS,代码行数:29,代码来源:PirepsController.php

示例6: change_password

 public function change_password($tmp_code = null)
 {
     $tmp_check = false;
     if (!Auth::check()) {
         $code_created = new Carbon($this->tmp_code_created);
         $tmp_check = !empty($this->tmp_code) && $this->tmp_code == $tmp_code && $code_created->diff(new Carbon())->days <= 7;
         if (!$tmp_check) {
             FormMessage::add('tmp_code', 'The code was incorrect');
             return false;
         }
     }
     $details = Request::all();
     $rules = array('new_password' => 'required|confirmed|min:4');
     if (!($tmp_check || Auth::check() && Auth::action('user.edit') && Auth::user()->id != $this->id)) {
         $rules['current_password'] = 'required';
     }
     $v = Validator::make($details, $rules);
     if ($v->passes()) {
         // check password
         if (!empty($rules['current_password']) && !Hash::check($details['current_password'], $this->password)) {
             FormMessage::add('current_password', 'The current password was incorrect');
             return false;
         }
         // if user can change his password then change it
         if (Auth::action('account.password', ['user_id' => $this->id]) || Auth::check() && Auth::action('user.edit')) {
             $this->password = Hash::make($details['new_password']);
             $this->tmp_code = '';
             $this->save();
             return true;
         }
     } else {
         FormMessage::set($v->messages());
     }
     return false;
 }
开发者ID:web-feet,项目名称:coasterframework,代码行数:35,代码来源:User.php

示例7: get_days

function get_days(Carbon $begin, Carbon $end = null) : array
{
    $end = $end ?? $begin;
    $diff = $begin->diff($end);
    $one_day = new DateInterval('P1D');
    $days = [];
    for ($i = 1; $i <= $diff->days; $i++) {
        $days[] = $begin->add($one_day)->getTimestamp();
    }
    return $days;
}
开发者ID:konato-events,项目名称:web,代码行数:11,代码来源:details.blade.php

示例8: scopeCalcDaysOpen

 public function scopeCalcDaysOpen($query, $created)
 {
     $created = new Carbon($created);
     $now = Carbon::now();
     if ($created->diff($now, false)->days < 0) {
         return 1;
     } else {
         //return "?";
         //return $created->diffInDays($now, false);
         return $created->diff($now, false)->days < 1 ? '1' : $created->diffInDays($now);
     }
     //return ($created->diff($now, false)->days < 0)	? '1' : $created->diffInDays($now);
 }
开发者ID:gfdeveloper,项目名称:LCCB,代码行数:13,代码来源:Request.php

示例9: progress

 /**
  * Returns delivery progress.
  *
  * @return {string} void
  */
 public function progress()
 {
     $events = $this->event->where('type', 'progress-event');
     if ($events->count() < 1) {
         return ['progress' => '0%', 'duration' => '0'];
     }
     $started = new Carbon($events->first()->created_at);
     $last = new Carbon($events->last()->created_at);
     $difference = $started->diff($last);
     $duration = implode([$difference->h, $difference->i, $difference->s], ':');
     $lastEvent = json_decode($events->last()['payload']);
     return ['progress' => $lastEvent->progress, 'duration' => $duration];
 }
开发者ID:DGZN,项目名称:monitor,代码行数:18,代码来源:Delivery.php

示例10: HasAccessAlbum

 public function HasAccessAlbum($idAlbum)
 {
     // return false;
     if (!$this->isAdmin()) {
         if ($this->profileD != null) {
             $IsActived = $this->profileD->actived;
             $created = new Carbon($this->profileD->FchVencimiento);
             $now = Carbon::now();
             $difference = $created->diff($now)->days;
             $profileAccessFull = $IsActived && $difference >= 0;
             if ($profileAccessFull) {
                 return true;
             }
         }
         return false;
     }
     return true;
 }
开发者ID:Jorgeachaar,项目名称:Krito,代码行数:18,代码来源:User.php

示例11: _change_password_checks

 private function _change_password_checks($code)
 {
     $this->layoutData['title'] = 'Forgotten Password';
     if (empty($code)) {
         $this->layoutData['content'] = 'Invalid Code!';
     } else {
         if (!($user = User::where('tmp_code', '=', $code)->first())) {
             $this->layoutData['content'] = 'Invalid Code!';
         } else {
             $code_created = new Carbon($user->tmp_code_created);
             $di = $code_created->diff(new Carbon('now'));
             if ($di->days > 7) {
                 $this->layoutData['content'] = 'This code has expired!';
             } else {
                 return $user;
             }
         }
     }
     return null;
 }
开发者ID:web-feet,项目名称:coasterframework,代码行数:20,代码来源:AccountController.php

示例12: confirm

 /**
  * Handles confirmation of the link
  * @param $request_link
  * @return int
  */
 public function confirm($request_link)
 {
     if (Bongo_request::where('request_link', '=', $request_link)->first() == null) {
         return 0;
     } elseif (Bongo_request::where('request_link', '=', $request_link)->first()->request_status != 1) {
         return 0;
     } else {
         $request = Bongo_request::where('request_link', '=', $request_link)->first();
         $created = new Carbon($request->created_at);
         $now = Carbon::now();
         $difference = $created->diff($now)->days > 7 ? $request->update(['request_status' => 2]) : $request->update(['request_status' => 1]);
         if ($request = Bongo_request::where('request_link', '=', $request_link)->first()) {
             if (\Md\User::where('email', '=', $request->bongo_email)->first() != null) {
                 return 1;
             } else {
                 return 2;
             }
         }
     }
 }
开发者ID:Jemok,项目名称:ba_hosting,代码行数:25,代码来源:BongoRequestRepo.php

示例13: ticketPerformance

 /**
  * Calculate the date length it took to solve a ticket
  * @param Ticket $ticket
  * @return integer|false
  */
 public function ticketPerformance($ticket)
 {
     if ($ticket->completed_at == null) {
         return false;
     }
     $created = new Carbon($ticket->created_at);
     $completed = new Carbon($ticket->completed_at);
     $length = $created->diff($completed)->days;
     return $length;
 }
开发者ID:darkflamed,项目名称:ticketit,代码行数:15,代码来源:TicketsController.php

示例14: date

 public function date($date)
 {
     $created = new Carbon($date);
     $now = Carbon::now();
     $difference = $created->diff($now)->days < 1 ? 'today' : $created->diffForHumans($now);
     $dates = explode(" ", $difference);
     if (count($dates) == 1) {
         return false;
     }
     return true;
 }
开发者ID:juan2ramos,项目名称:credito,代码行数:11,代码来源:CreditController.php

示例15: getDiff

 private function getDiff(Carbon $time1, Carbon $time2)
 {
     return $time2->diff($time1);
 }
开发者ID:jrsalunga,项目名称:gi-cashier,代码行数:4,代码来源:Timesheet.php


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