本文整理汇总了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";
}
示例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');
}
}
示例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;
}
示例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]);
}
示例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]);
}
示例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;
}
示例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;
}
示例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);
}
示例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];
}
示例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;
}
示例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;
}
示例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;
}
}
}
}
示例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;
}
示例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;
}
示例15: getDiff
private function getDiff(Carbon $time1, Carbon $time2)
{
return $time2->diff($time1);
}