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


PHP Carbon::diffInDays方法代码示例

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


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

 /**
  * Show the board index for the user.
  *
  * @return Response
  */
 public function getContribute()
 {
     $devStart = new Carbon(static::$ContributeProjectStart);
     $devCarbon = new Carbon(static::$ContributePublicStart);
     $devTimeSum = 0;
     $devTimer = "0 hours";
     $donorGroups = Payment::getDonorGroups();
     $donorWeights = ['uber' => 25, 'plat' => 20, 'gold' => 15, 'silver' => 10, 'bronze' => 10];
     foreach ($donorGroups as $donorGroup) {
         foreach ($donorGroup as $donor) {
             // Add the amount to the dev timer.
             $devTimeSum += $donor->amount;
         }
     }
     // Determine the time in a literal string.
     $devHours = 0;
     $devDays = 0;
     $devInflation = static::$ContributeDevInflation;
     // This inflation factor will make the dev timer reflect off hours too, on the assumption of a 40 hour work week.
     $devTime = $devTimeSum / 100 / (double) env('CONTRIB_HOUR_COST', 10) * $devInflation;
     $devCarbon->addHours($devTime);
     $devDays = $devCarbon->diffInDays();
     $devHours = $devCarbon->diffInHours() - $devDays * 24;
     if ($devHours > 0 || $devDays > 0) {
         $devTimer = "";
         if ($devDays > 0) {
             if ($devDays != 1) {
                 $devTimer .= "{$devDays} days";
             } else {
                 $devTimer .= "{$devDays} day";
             }
             if ($devHours > 0) {
                 $devTimer .= " and ";
             }
         }
         if ($devHours > 0) {
             if ($devHours != 1) {
                 $devTimer .= "{$devHours} hours";
             } else {
                 $devTimer .= "{$devHours} hour";
             }
         }
     }
     return $this->view(static::VIEW_CONTRIBUTE, ["devCarbon" => $devCarbon, "devTimer" => $devTimer, "devStart" => $devStart, "donations" => $devTimeSum, "donors" => $donorGroups, "donorWeight" => $donorWeights]);
 }
开发者ID:LulzNews,项目名称:infinity-next,代码行数:50,代码来源:PageController.php

示例3: show

 public function show($id)
 {
     $member = Member::find($id);
     $birthDate = $member->birthday;
     $birthDate = explode("-", $birthDate);
     $member->age = Carbon::createFromDate($birthDate[0], $birthDate[1], $birthDate[2])->age;
     $meses = array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
     $dias = array("Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado");
     $currentdate = Carbon::today();
     $sumaAffiliations = $member->affiliations->sum('price');
     $affiliations = $member->affiliations;
     $affiliationActives = \App\Affiliation::orderBy('finalization', 'DEC')->where('member_id', $member->id)->where('finalization', '>=', $currentdate)->get();
     $affiliationInactives = \App\Affiliation::orderBy('finalization', 'DEC')->where('member_id', $member->id)->where('finalization', '<', $currentdate)->get();
     $member->affiliations = $affiliationActives;
     if ($affiliationActives->first() != null) {
         $memshipactiva = $affiliationActives->last();
         $initiation = new Carbon($memshipactiva->initiation);
         $finalization = new Carbon($memshipactiva->finalization);
         $corrido = $initiation->diffInDays($currentdate);
         if ($initiation->lt($currentdate)) {
             $diference = $initiation->diffInDays($finalization);
             $porcentaje = $corrido / $diference * 100;
         } else {
             $porcentaje = 0;
         }
         $memshipactiva->porcentaje = $porcentaje;
     } else {
         $memshipactiva = null;
     }
     $saldo = $sumaAffiliations - $member->payments->sum('amount');
     $member->saldo = $saldo;
     $member->sumaPagos = $member->payments->sum('amount');
     $member->sumaAffiliations = $sumaAffiliations;
     if ($member->sumaPagos == 0 and $sumaAffiliations == 0) {
         //no tiene pagos ni afiliaciones
         $member->difUltimoPago = -1;
     } elseif ($member->sumaPagos <= 0 and $sumaAffiliations > 0) {
         //no tiene pagos pero si tiene afiliaciones
         $fechaUltimoPago = \App\Affiliation::orderBy('created_at', 'asc')->where('member_id', $member->id)->first();
         $fechaUltimoPago = new Carbon($fechaUltimoPago->created_at);
         $difUltimoPago = $fechaUltimoPago->diffInDays($currentdate);
         $member->difUltimoPago = $difUltimoPago;
     } elseif ($member->sumaPagos > 0 and $sumaAffiliations > 0) {
         // tiene afiliaciones y pagos
         $fechaUltimoPago = new Carbon($member->payments->first()->created_at);
         $difUltimoPago = $fechaUltimoPago->diffInDays($currentdate);
         $member->difUltimoPago = $difUltimoPago;
     }
     return view('member.show', ['member' => $member, 'meses' => $meses, 'dias' => $dias, 'activa' => $memshipactiva, 'inactivas' => $affiliationInactives]);
 }
开发者ID:StivenSerna,项目名称:gym,代码行数:50,代码来源:MembersController.php

示例4: days

 /**
  * Gets the number of days that a date range spans.
  *
  * This is not possible, for obvious reasons, on open ended or open start date ranges.
  *
  * @throws Exception
  *
  * @return int
  */
 public function days()
 {
     if ($this->isOpenEnded() || $this->isOpenStarted()) {
         throw new Exception('The number of days within a range cannot be calculated for ranges that are open ended or open started.');
     }
     return $this->after->diffInDays($this->before);
 }
开发者ID:20TRIES,项目名称:date_range,代码行数:16,代码来源:DateRange.php

示例5: dateRange

 public function dateRange()
 {
     $start = new Carbon(Input::get('start'));
     $end = new Carbon(Input::get('end'));
     $diff = $start->diffInDays($end);
     if ($diff > 50) {
         Session::flash('warning', $diff . ' days of data may take a while to load.');
     }
     Session::put('start', $start);
     Session::put('end', $end);
 }
开发者ID:leander091,项目名称:firefly-iii,代码行数:11,代码来源:HomeController.php

示例6: getProcessDaysAttribute

 public function getProcessDaysAttribute()
 {
     $days = 0;
     if ($this->state === 'PR') {
         $dt = new Carbon($this->updated_at);
         $days = $dt->diffInDays($this->created_at);
     } else {
         $now = new Carbon();
         $days = $now->diffInDays($this->created_at);
     }
     return $days;
 }
开发者ID:sibasbo,项目名称:sibas,代码行数:12,代码来源:Facultative.php

示例7: create

 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create($member_id)
 {
     $memberships = Membership::all()->lists('description', 'id');
     $membershipsAll = Membership::all();
     $member = Member::find($member_id);
     $rangeArray = array();
     $rangeDates = \App\Affiliation::orderBy('finalization', 'DEC')->where('member_id', $member_id)->where('finalization', '>=', Carbon::now())->get();
     foreach ($rangeDates as $range) {
         $initiationRange = new Carbon($range->initiation);
         $finalizationRange = new Carbon($range->finalization);
         $diference = $initiationRange->diffInDays($finalizationRange);
         for ($i = 0; $i <= $diference; $i++) {
             array_unshift($rangeArray, "'" . $initiationRange->copy()->format('Y-m-d') . "'");
             $initiationRange->addDay();
         }
     }
     return view('affiliation.create')->with('memberships', $memberships)->with('membershipsAll', $membershipsAll)->with('member', $member)->with('affiliationRange', $rangeArray);
 }
开发者ID:StivenSerna,项目名称:gym,代码行数:23,代码来源:AffiliationsController.php

示例8: proyectosempresa

 public function proyectosempresa()
 {
     $proyectos = $this->user->proyectos;
     $now = Carbon::now();
     $i = 0;
     foreach ($proyectos as $proyecto) {
         $proyecto["pruebas"] = Prueba::where('proyecto_id', $proyecto["id"])->get();
         $proyectos[$i]["resultados"] = Resultado::where('proyecto_id', $proyecto["id"])->get();
         $created = new Carbon($proyecto["created_at"]);
         $last = $created->diffInDays($now);
         $i++;
     }
     $personal = Personal::where('user_id', $this->user->id)->get();
     if (count($proyectos) == 0) {
         $last = 10;
     }
     return view('proyectos', compact('proyectos', 'last', 'personal'));
 }
开发者ID:gerardo15,项目名称:Puzzle,代码行数:18,代码来源:EmpresaController.php

示例9: save

 /**
  * Saves new vacation entry to database and returns status in json response
  *
  * @TODO: move logic out of controller
  *
  * @param Request $request
  * @return array
  */
 public function save(Request $request)
 {
     $employee = $this->employee->find($request->input('employee_id'));
     $vacationStart = new Carbon($request->input('start'));
     $vacationEnd = new Carbon($request->input('end'));
     $duration = $vacationStart->diffInDays($vacationEnd);
     if ($duration > $employee->vacationsLeft || $vacationEnd <= $vacationStart) {
         return ['status' => 403];
     }
     $overlapingVacations = $employee->vacations()->where('end', '>', $vacationStart)->where('start', '<', $vacationEnd)->get();
     if (!$overlapingVacations->isEmpty()) {
         return ['status' => 403];
     }
     $vacation = $this->vacation->create($request->all());
     $vacation->duration = $duration;
     if ($vacation->save()) {
         return ['status' => 200];
     }
     return ['status' => 500];
 }
开发者ID:emaslak,项目名称:simpleHR,代码行数:28,代码来源:VacationController.php

示例10: dateRange

 /**
  * @param Request $request
  */
 public function dateRange(Request $request)
 {
     $start = new Carbon($request->get('start'));
     $end = new Carbon($request->get('end'));
     $label = $request->get('label');
     $isCustomRange = false;
     Log::debug('Received dateRange', ['start' => $request->get('start'), 'end' => $request->get('end'), 'label' => $request->get('label')]);
     // check if the label is "everything" or "Custom range" which will betray
     // a possible problem with the budgets.
     if ($label === strval(trans('firefly.everything')) || $label === strval(trans('firefly.customRange'))) {
         $isCustomRange = true;
         Log::debug('Range is now marked as "custom".');
     }
     $diff = $start->diffInDays($end);
     if ($diff > 50) {
         Session::flash('warning', strval(trans('firefly.warning_much_data', ['days' => $diff])));
     }
     Session::put('is_custom_range', $isCustomRange);
     Session::put('start', $start);
     Session::put('end', $end);
 }
开发者ID:roberthorlings,项目名称:firefly-iii,代码行数:24,代码来源:HomeController.php

示例11: getDeadLineDifference

 public function getDeadLineDifference(Info $info, Carbon $f_deadline, Carbon $l_deadline)
 {
     // Get first and last deadlines difference in days
     $days = $f_deadline->diffInDays($l_deadline);
     $c = 0;
     for ($m = 0; $m < $days; $m++) {
         $current = $f_deadline->addDay(1);
         // If the day after first deadline is not Saturday or Sunday, count as 1 working day
         if ($current->dayOfWeek != Carbon::SATURDAY && $current->dayOfWeek != Carbon::SUNDAY) {
             $c += 1;
         }
     }
     return $c;
 }
开发者ID:neutt22,项目名称:claims-system,代码行数:14,代码来源:Info.php

示例12: financingSuccess

 public function financingSuccess()
 {
     $financeArray = Input::get('financeArray');
     $financingDate = Input::get('financingDate');
     $fundingDate = new Carbon($financingDate);
     $lastBill = Bill::orderBy('bill_date', 'desc')->first();
     if (count($lastBill) > 0) {
         $lastBillCarbon = new Carbon($lastBill->bill_date);
         $diffBillsDate = $lastBillCarbon->diffInDays($fundingDate, false);
     } else {
         $diffBillsDate = 1;
     }
     $messageArray = [];
     foreach ($financeArray as $key) {
         $finance = Finance::find($key);
         $registryDate = new Carbon($finance->date_of_registry);
         $diffDate = $registryDate->diffInDays($fundingDate, false);
         if ($diffBillsDate > 0) {
             if ($diffDate >= 0) {
                 if ($finance->type_of_funding === 'Первый платеж') {
                     $deliveryToFinances = $finance->deliveryToFinance;
                     //проверка лимита
                     $relation = $deliveryToFinances->first()->delivery->relation;
                     $usedLimit = 0;
                     $usedLimit = $relation->deliveries()->where('state', false)->where('status', 'Профинансирована')->sum('balance_owed');
                     $limit = $relation->limit;
                     if ($limit) {
                         $limitValue = $limit->value;
                         $freeLimit = $limitValue - $usedLimit;
                         if ($finance->sum <= $freeLimit) {
                             $finance->date_of_funding = $financingDate;
                             $finance->status = 'Подтверждено';
                             if ($finance->save()) {
                                 foreach ($deliveryToFinances as $deliveryToFinance) {
                                     $delivery = $deliveryToFinance->delivery;
                                     $delivery->date_of_funding = $financingDate;
                                     $delivery->status = 'Профинансирована';
                                     // $delivery->stop_commission = true;
                                     $delivery->save();
                                 }
                             }
                             $callback = 'success';
                             $messageShot = 'Успешно!';
                             $message = 'Финансирование для клиента ' . $finance->client . ' подтверждено';
                             array_push($messageArray, ['callback' => $callback, 'message' => $message, 'message_shot' => $messageShot, 'type' => true, 'data' => $key]);
                         } else {
                             $callback = 'danger';
                             $messageShot = 'Ошибка!';
                             $message = 'Превышен лимит для связи. Клиент: ' . $relation->client->name . ' и Дебитор: ' . $relation->debtor->name;
                             array_push($messageArray, ['callback' => $callback, 'message' => $message, 'message_shot' => $messageShot]);
                         }
                     } else {
                         $callback = 'danger';
                         $messageShot = 'Ошибка!';
                         $message = 'Лимит для связи не найден. Клиент: ' . $relation->client->name . ' и Дебитор: ' . $relation->debtor->name;
                         array_push($messageArray, ['callback' => $callback, 'message' => $message, 'message_shot' => $messageShot]);
                     }
                 } else {
                     $finance->date_of_funding = $financingDate;
                     $finance->status = 'Подтверждено';
                     $finance->save();
                     $callback = 'success';
                     $messageShot = 'Успешно!';
                     $message = 'Финансирование для клиента ' . $finance->client . ' подтверждено';
                     array_push($messageArray, ['callback' => $callback, 'message' => $message, 'message_shot' => $messageShot, 'type' => false]);
                 }
             } else {
                 $callback = 'danger';
                 $messageShot = 'Ошибка!';
                 $message = 'Дата реестра превышает дату финансирования';
                 array_push($messageArray, ['callback' => $callback, 'message' => $message, 'message_shot' => $messageShot]);
             }
         } else {
             $callback = 'danger';
             $messageShot = 'Ошибка!';
             $message = 'Финансирование поставки в закрытом месяце- запрещено!';
             array_push($messageArray, ['callback' => $callback, 'message' => $message, 'message_shot' => $messageShot]);
         }
     }
     return $messageArray;
 }
开发者ID:PixelPartyRu,项目名称:erp,代码行数:81,代码来源:FinanceController.php

示例13: recalculateDailyCharge

 public function recalculateDailyCharge($repayment, $deliveryId)
 {
     $allDailyArray = [];
     $nds = 18;
     $dateNow = new Carbon(date('Y-m-d'));
     $dateOfRepayment = new Carbon($repayment->date);
     $fixedCharge = false;
     $delivery = Delivery::find($deliveryId);
     $relation = $delivery->relation;
     //связь
     $tariff = $relation->tariff;
     //тарифы
     $dateOfRepaymentClone = clone $dateOfRepayment;
     $dateOfFunding = new Carbon($delivery->date_of_funding);
     $percent_commission = $tariff->commissions->where('type', 'finance')->first();
     $udz_commission = $tariff->commissions->where('type', 'udz')->first();
     $penalty_commission = $tariff->commissions->where('type', 'peni')->first();
     $fixed_commission = $tariff->commissions()->where('type', 'document')->first();
     $dateOfRecourse = new Carbon($delivery->date_of_recourse);
     $dateOfRepaymentDiff = $dateOfRepayment->diffInDays($dateNow, false);
     $dateOfRepaymentFundingDiff = $dateOfFunding->diffInDays($dateOfRepayment, false);
     if ($dateOfRepaymentFundingDiff <= 0) {
         $fixedCharge = true;
     }
     for ($i = 0; $i < $dateOfRepaymentDiff; $i++) {
         $dailyArray = [];
         $dateNowVar = $dateOfRepaymentClone->addDays(1);
         $dateOfFundingDiffTest = $dateOfFunding->diffInDays($dateNowVar, false);
         $daysInYear = date("L", mktime(0, 0, 0, 7, 7, $dateNowVar->year)) ? 366 : 365;
         $actualDeferment = $dateOfRecourse->diffInDays($dateNowVar, false);
         //Фактическая просрочка
         $dailyFixed = 0;
         $dailyFixedNds = 0;
         if ($fixedCharge == true && $i == 0) {
             if ($fixed_commission) {
                 $fixed_charge_w_nds = $fixed_commission->commission_value;
                 $dailyFixed = $fixed_charge_w_nds;
                 if ($fixed_commission->nds == true) {
                     $fixed_charge_nds = $fixed_charge_w_nds / 100.0 * $nds;
                     $dailyFixedNds = $fixed_charge_nds;
                 }
             }
         }
         $dailyPercent = 0;
         $dailyPercentNds = 0;
         //        //Процент
         if ($percent_commission) {
             //Годовые/дни
             $handle = $percent_commission->additional_sum;
             if ($percent_commission->rate_stitching == true) {
                 $percent = $percent_commission->commission_value / $daysInYear;
             } else {
                 $percent = $percent_commission->commission_value;
             }
             //От финансирование либо накладной
             if ($handle == true) {
                 $dailyPercent = $delivery->balance_owed / 100.0 * $percent;
             } else {
                 $dailyPercent = $delivery->remainder_of_the_debt_first_payment / 100.0 * $percent;
             }
             if ($percent_commission->nds == true) {
                 $dailyPercentNds = $dailyPercent / 100.0 * $nds;
             }
         }
         $dailyUdz = 0;
         $dailyUdzNds = 0;
         if ($udz_commission) {
             $dayOrYear = $udz_commission->rate_stitching;
             //Нахождение разницы
             $handle = $udz_commission->additional_sum;
             //проверка накладной и финансирования
             if ($handle == true) {
                 $waybillOrFirstPayment = $delivery->balance_owed;
             } else {
                 $waybillOrFirstPayment = $delivery->remainder_of_the_debt_first_payment;
             }
             $rage = $udz_commission->commissionsRages()->where('min', '<=', $dateOfFundingDiffTest)->where(function ($query) use($dateOfFundingDiffTest) {
                 $query->where('max', '>=', $dateOfFundingDiffTest)->orWhere('max', '=', 0);
             })->first();
             if ($rage) {
                 if ($dayOrYear == true) {
                     $udz = $rage->value / $daysInYear;
                 } else {
                     $udz = $rage->value;
                 }
                 $dailyUdz = $waybillOrFirstPayment / 100.0 * $udz;
                 //Ндс
                 if ($udz_commission->nds == true) {
                     $dailyUdzNds = $dailyUdz / 100.0 * $nds;
                 }
             }
         } else {
             // var_dump('Коммиссии не найдено');
         }
         // //         //Пеня за просрочку
         $dailyDeferment = 0;
         $dailyDefermentNds = 0;
         if ($penalty_commission) {
             $dayOrYear = $penalty_commission->rate_stitching;
             //Нахождение разницы
//.........这里部分代码省略.........
开发者ID:PixelPartyRu,项目名称:erp,代码行数:101,代码来源:RepaymentController.php

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

示例15: fatorVencimento

 /**
  * Calcula o fator vencimento.
  * 
  * @param  Carbon $data
  * @return integer
  */
 public static function fatorVencimento(Carbon $data)
 {
     $dataBase = new Carbon("1997-10-07");
     return $data->diffInDays($dataBase);
 }
开发者ID:wfcreations,项目名称:ya-boleto-php,代码行数:11,代码来源:Number.php


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