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


PHP Carbon::diffInYears方法代码示例

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


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

示例1: 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

示例2: lengthInYears

 /**
  * Get the difference between start and end dates of the period in years.
  *
  * @return int
  */
 public function lengthInYears()
 {
     return $this->startDate->diffInYears($this->endDate);
 }
开发者ID:asdf20122012,项目名称:carbon-period,代码行数:9,代码来源:CarbonPeriod.php

示例3: report

 /**
  * [report description]
  * @param  [type] $token [description]
  * @return [type]        [description]
  */
 public function report($token)
 {
     $affiliate = $this->affiliateRepository->token($token);
     //Total dues for Affiliate
     $duesAffiliate = $this->duesRepository->getModel()->where('type', 'affiliate')->where('affiliate_id', $affiliate->id)->orderBy('date_payment', 'ASC')->get();
     //Total dues for Private
     $duesPrivate = $this->duesRepository->getModel()->where('type', 'privado')->where('affiliate_id', $affiliate->id)->orderBy('date_payment', 'ASC')->get();
     $error = '';
     $page = 'Afiliados';
     if ($duesAffiliate->isEmpty()) {
         $error_affiliate = true;
     }
     if ($duesPrivate->isEmpty()) {
         $error_private = true;
     }
     if (isset($error_private) && isset($error_affiliate)) {
         $error = "El afiliado {$affiliate->fname} {$affiliate->flast} no cuenta con cuotas canceladas.";
         return view('errors.validate', compact('page', 'error'));
     }
     //Birthdate
     $birthdate = new Carbon($affiliate->birthdate);
     //Age
     $age = $birthdate->diffInYears(Carbon::now());
     //Format Birthdate
     $birthdate = $birthdate->format('d/m/Y');
     //Data for report affiliate
     $dataAffiliate = $this->prepareData($duesAffiliate, 'affiliate');
     //Data for report private
     $dataPrivate = $this->prepareData($duesPrivate, 'privado');
     //Dues total max, date of admission
     $dues_total_max = 0;
     if ($dataAffiliate[count($dataAffiliate) - 1][2] >= $dataPrivate[count($dataPrivate) - 1][2]) {
         $dues_total_max = $dataAffiliate[count($dataAffiliate) - 1][2];
         $date_of_admission = $dataAffiliate[count($dataAffiliate) - 1][0];
     } else {
         $dues_total_max = $dataPrivate[count($dataPrivate) - 1][2];
         $date_of_admission = $dataPrivate[count($dataPrivate) - 1][0];
     }
     //Date Now separed Date of Hours
     $arrDateNow = $this->arrDateNow();
     $pdf = \PDF::loadView('affiliates.report.main', compact('arrDateNow', 'affiliate', 'birthdate', 'age', 'date_of_admission', 'dataPrivate', 'dues_total_max', 'dataAffiliate'))->setOrientation('portrait');
     return $pdf->stream("Reporte Contribución Afiliado -" . $affiliate->fullname() . ".pdf");
 }
开发者ID:asarmiento,项目名称:CPHon,代码行数:48,代码来源:AffiliatesController.php

示例4: age

 /**
  *
  *Get the age from the given date
  */
 public function age()
 {
     $myTime = new Carbon($this->date_of_birth);
     return $myTime->diffInYears();
 }
开发者ID:razikallayi,项目名称:peaceschools,代码行数:9,代码来源:User.php


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