public function getDateAdmissionAttribute() { $now = new Carbon(); $dt = new Carbon($this->created_at); $dt->setLocale('es'); return $dt->diffForHumans($now); }
public function get_warnings_object() { //Get the users warnings from the Database $warnings = DB::connection('server')->table('warnings')->where('ckey', '=', $this->player_ckey)->where('visible', '=', '1')->get(); //Transform the timestamps to Ago strings foreach ($warnings as $warning) { $carbon = new Carbon($warning->time); $warning->diff = $carbon->diffForHumans(); } return $warnings; }
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"; }
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; }
/** * Dodatkowe filtry Twig zwiazane z formatowaniem danych uzytkownika * * @return array */ public function getFilters() { return [new Twig_SimpleFilter('format_date', function ($dateTime, $diffForHumans = true) { $format = Auth::check() ? auth()->user()->date_format : '%Y-%m-%d %H:%M'; if (!$dateTime instanceof Carbon) { $dateTime = new Carbon($dateTime); } $now = Carbon::now(); if (!$diffForHumans) { return $dateTime->formatLocalized($format); } elseif ($dateTime->diffInHours($now) < 1) { return $dateTime->diffForHumans(null, true) . ' temu'; } elseif ($dateTime->isToday()) { return 'dziś, ' . $dateTime->format('H:i'); } elseif ($dateTime->isYesterday()) { return 'wczoraj, ' . $dateTime->format('H:i'); } else { return $dateTime->formatLocalized($format); } }), new Twig_SimpleFilter('timestamp', function ($dateTime) { if ($dateTime instanceof Carbon) { return $dateTime->getTimestamp(); } else { return strtotime($dateTime); } })]; }
<?php require_once 'vendor/autoload.php'; use Carbon\Carbon; use Citco\Carbon as CitcoCarbon; use CarbonExt\FiscalYear\Calculator; // Object Instantiation $brisbane = new Carbon('2015-12-01', 'Australia/Brisbane'); $newYorkCity = new Carbon('2015-12-01', 'America/New_York'); $dtBerlin = new Carbon('2015-12-01', 'Europe/Berlin'); $outputString = "Time difference between %s & %s: %s hours.\n"; // Date difference printf($outputString, "Berlin", "Brisbane, Australia", $dtBerlin->diffInHours($brisbane, false)); printf($outputString, "Berlin", "New York City, America", $dtBerlin->diffInHours($newYorkCity, false)); $septEighteen2014 = Carbon::createFromDate(2014, 9, 18, $dtBerlin->getTimezone()); printf("difference between now and %s in \n\thours: %d, \n\tdays: %d, \n\tweeks: %d, \n\tweekend days: %d, \n\tweek days: %s, \n\thuman readable: %s\n", $septEighteen2014->toFormattedDateString(), $dtBerlin->diffInHours($septEighteen2014), $dtBerlin->diffInDays($septEighteen2014), $dtBerlin->diffInWeeks($septEighteen2014), $dtBerlin->diffInWeekendDays($septEighteen2014), $dtBerlin->diffInWeekDays($septEighteen2014), $dtBerlin->diffForHumans($septEighteen2014)); // Date formatting echo $dtBerlin->toDateString() . "\n"; echo $dtBerlin->toFormattedDateString() . "\n"; echo $dtBerlin->toTimeString() . "\n"; echo $dtBerlin->toDateTimeString() . "\n"; echo $dtBerlin->toDayDateTimeString() . "\n"; echo $dtBerlin->toRfc1036String() . "\n"; echo $dtBerlin->toAtomString() . "\n"; echo $dtBerlin->toCookieString() . "\n"; echo $dtBerlin->toRssString() . "\n"; $dtBerlin->setToStringFormat('l jS \\of F Y'); echo $dtBerlin . "\n"; echo (int) $dtBerlin->isLeapYear() . "\n"; // is* range of functions test printf("Is yesterday? %s\n", $dtBerlin->isYesterday() ? "yes" : "no");
public function getLastUpdatedRelative() { $date = new Carbon($this->updated_at); return $date->diffForHumans(); }
public function ago(Carbon $other = null, $absolute = false) { $diff = parent::diffForHumans($other, $absolute); $pattern = array("years", "months", "days", "weeks", "hours", "minutes", "seconds", "year", "month", "day", "week", "hour", "minute", "second", "from now", "ago", "after", "before"); $replace = array("سال", "ماه", "روز", "هقته", "ساعت", "دقیقه", "ثانیه", "سال", "ماه", "روز", "هقته", "ساعت", "دقیقه", "ثانیه", "از الان", "پیش", "بعد", "قبل"); return str_replace($pattern, $replace, $diff); }
</a> </li> <li> <a href="#" title="" data-toggle="tooltip" data-container="body" data-original-title="0 nouveau badge"> <i class="fa fa-trophy"></i> </a> </li> </ul> <div class="last-visit"> <p><b>Last visit :</b></p> <p class="text-center"> About <?php $last = new Carbon(Auth::user()->last_login); $now = Carbon::now(); echo $last->diffForHumans($now, true); ?> ago </p> </div> </div> </div> <div class="col-sm-8 col-xs-12"> <div class="block-group scheme-blue"> <div class="block block-sm hidden-xs"> <div class="inline-left color-white"><strong>Level progress:</strong></div> <div class="inline-full"> <div class="progress progress-sm"> <div class="progress-bar" role="progressbar" style="width: {{$level['percent']}}%"> </div> </div>
switch ($c) { case 'f': $url = new Facebook(); return $url->getLoginUrl(); case 'g': $client = new Google_Client(); $auth = new GoogleModel($client); return $auth->getAuthUrl(); } }, 'is_loggedin' => function () { $u = new User(); return $u->isLoggedIn(); }, 'time' => function ($time) { $t = new Carbon($time); return $t->toRfc850String(); }, 'readable_time' => function ($time) { $t = new Carbon($time); return $t->diffForHumans(); }, 'strip' => function ($string) { // strip tags to avoid breaking any html $string = strip_tags($string); if (strlen($string) > 500) { // truncate string $stringCut = substr($string, 0, 500); // make sure it ends in a word so assassinate doesn't become ass... $string = substr($stringCut, 0, strrpos($stringCut, ' ')); } return nl2br($string); }], 'filters' => ['e' => function ($str) { return Func::escape($str); }]];
/** * @param Carbon /Carbon $created string * @param $absolute bool * * @return string * */ static function timeDifference($created, $absolute = true) { $carbon = new Carbon(); return $carbon->diffForHumans($created, $absolute); }
private function setDateTime(Carbon $datetime) { return $datetime->year > 0 ? $datetime . "<br/><small>(" . $datetime->diffForHumans() . ")</small>" : "-"; }
public function getDateDiffForHumans($field) { $carbon = new Carbon($this->{$field}); return $carbon->diffForHumans(); }
public static function StandardDateHTML(Carbon $date, $includetime = false, $comparetonow = false, $includeicon = false) { $output = ''; $close = clone $date; $close = $close->addDays(-5); if ($comparetonow) { $now = Carbon::today(); if ($date <= $now) { $output .= '<span class="text-danger">'; } elseif ($close <= $now) { $output .= '<span class="text-warning">'; } else { $output .= '<span>'; } } else { $output .= '<span>'; } if ($includeicon) { $output .= '<i class="fa fa-clock-o"></i> '; } $output .= $date->diffForHumans(); $output .= '<br/>'; if ($includetime) { $output .= ' <small>( ' . $date->format('d M Y h:s') . ' )</small>'; } else { $output .= ' <small>( ' . $date->format('d M Y') . ' )</small>'; } $output .= '</span>'; return $output; }
/** * *Get the message sent time in human readable form */ public function sendAt() { $myTime = new Carbon($this->created_at); return $myTime->diffForHumans(); }
public static function ageInDays(Carbon $date) : string { return number_format(round($date->diffInMinutes() / (24 * 60), 2), 2) . ' (' . $date->diffForHumans() . ')'; }
/** * @param Carbon $carbon * @param string $originalFieldName * @return \Illuminate\Support\Collection */ public function convertTimeFieldToHumanReadable(Carbon $carbon, $originalFieldName = '') { $dataFieldName = $originalFieldName ?: 'date'; return collect([$dataFieldName => $carbon->toDateTimeString(), 'human' => $carbon->diffForHumans(Carbon::now())]); }
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; }
protected function formatDate(Carbon $date) { return ['rfc3339' => $date->toRfc3339String(), 'timestamp' => $date->getTimestamp(), 'diffForHumans' => $date->diffForHumans()]; }
/** * Get updated_at variable with the given format * * @param string $value [] * @return string */ public function getCreatedAtAttribute($value) { $time = new Carbon($value); return $time->diffForHumans(); }
public static function date(Carbon $date) { if ($date->diffInDays(Carbon::now()) < 7) { return $date->diffForHumans(); } else { return $date->toFormattedDateString(); } }