本文整理汇总了PHP中Carbon\Carbon::addHours方法的典型用法代码示例。如果您正苦于以下问题:PHP Carbon::addHours方法的具体用法?PHP Carbon::addHours怎么用?PHP Carbon::addHours使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carbon\Carbon
的用法示例。
在下文中一共展示了Carbon::addHours方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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]);
}
示例2: each
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");
printf("Is a Thursday? %s\n", $dtBerlin->isThursday() ? "yes" : "no");
printf("Is in the future? %s\n", $dtBerlin->isFuture() ? "yes" : "no");
printf("Is a leap year? %s\n", $dtBerlin->isLeapYear() ? "yes" : "no");
// first and last of the month
printf("First of the month %s\n", $dtBerlin->firstOfMonth());
printf("Last of the month %s\n", $dtBerlin->lastOfMonth());
// nthOf* function test
printf("Start of the month %s\n", $dtBerlin->startOfMonth());
printf("End of the month %s\n", $dtBerlin->endOfMonth());
printf("End of the decade %s\n", $dtBerlin->endOfDecade());
// Date manipulation
print $dtBerlin->addHours(5)->addDays(2)->addWeeks(1)->addMonths(3);
print $dtBerlin->subMonths(8)->subHours(7);
// Find UK Bank Holidays
$dtLondon = CitcoCarbon::today('Europe/London');
list($date, $name) = each($dtLondon->nextBankHoliday());
printf("The next bank holiday is %s on %s\n", $name, $date);
foreach ($dtLondon->getBankHolidays([2016, 2017]) as $date => $name) {
printf("The next bank holiday is %s on %s\n", $name, $date);
}
// Find end of the current financial year
$fyCalculator = new Calculator(7, 1);
/* FY starts on July 1 */
print $fyCalculator->get($dtBerlin);
示例3: setStatusAttribute
/**
* @param boolean checks that the user is an admin, returns false if not. Automatically sets the closing time to be one week out from now.
*/
public function setStatusAttribute($value)
{
//Coverts value to the integer if not set
if (!is_numeric($value)) {
switch ($value) {
case 'draft':
$value = 0;
break;
case 'review':
$value = 1;
break;
case 'published':
$value = 2;
break;
case 'closed':
$value = 3;
break;
}
}
/* I am not exactly sure I agree with this. I think this is too opinionated. Especially
* if a motion gets published before it was ready to be. Doesn't really give the user
* much leeway.
*/
// if(isset($this->attributes['status']) && $value < $this->attributes['status']){
// abort(403,"You can not switch a status back");
// }
switch ($value) {
case 0:
$this->attributes['status'] = 0;
break;
case 1:
$this->attributes['status'] = 1;
break;
case 2:
if (Auth::check() && !Auth::user()->can('administrate-motions')) {
abort(401, "Unable to set user does not have permission to set motions as active");
}
if ($value && !$this->motionRanks->isEmpty()) {
abort(403, "This motion has already been voted on, it cannot be reactivated after closing");
}
$this->attributes['status'] = 2;
if (!$this->closing && $value == 1) {
$closing = new Carbon();
$closing->addHours(Setting::get('motion.default_closing_time_delay', 72));
$this->closing = $closing;
}
break;
case 3:
$this->attributes['status'] = 3;
break;
}
return true;
}
示例4: setStatusAttribute
/**
* @param boolean checks that the user is an admin, returns false if not. Automatically sets the closing time to be one week out from now.
*/
public function setStatusAttribute($value)
{
//Coverts value to the integer if not set
if (!is_numeric($value)) {
switch ($value) {
case 'draft':
$value = 0;
break;
case 'review':
$value = 1;
break;
case 'published':
$value = 2;
break;
case 'closed':
$value = 3;
break;
}
}
if ($value < $this->attributes['status']) {
abort(403, "You can not switch a status back");
}
switch ($value) {
case 0:
$this->attributes['status'] = 0;
break;
case 'review':
$this->attributes['status'] = 1;
break;
case 'published':
if (Auth::check() && !Auth::user()->can('administrate-motions')) {
abort(401, "Unable to set user does not have permission to set motions as active");
}
if ($value && !$this->motionRanks->isEmpty()) {
abort(403, "This motion has already been voted on, it cannot be reactivated after closing");
}
$this->attributes['status'] = 2;
if (!$this->closing && $value == 1) {
$closing = new Carbon();
$closing->addHours(Setting::get('motion.default_closing_time_delay', 72));
$this->closing = $closing;
}
break;
case 'closed':
$this->attributes['status'] = 3;
break;
}
return true;
}
示例5: missedTrips
/**
* check for missed trip check outs
**/
public function missedTrips()
{
$trips = TripPlan::active()->notified()->get();
foreach ($trips as $trip) {
//capture current time
$now = Carbon::now();
//set up values for trip end and timer, accounting for User's UTC offset
$end_time = new Carbon($trip->end_time, $trip->offset);
//parse alert_timer into hours and minutes
$alert_timer = explode(":", $trip->alert_timer);
//add hours and minutes from timer to end_time
$notifyTime = $end_time->addHours($alert_timer[0])->addMinutes($alert_timer[1]);
//compare current time to notification threshold
if ($now->gte($notifyTime)) {
//notify users emergency contacts
$this->notifyEmergencyContacts($trip);
//set notified flag
$trip->notified = 1;
$trip->save();
}
}
}
示例6: getRfcCompliantDate
/**
* Return an RFC {large number here} compliant date from a Carbon date object
*
* Example: Wed, 21 Oct 2015 13:48:28 GMT
*
* @param \Carbon\Carbon $carbon
* @param int $offset
* @return string
*/
private function getRfcCompliantDate(Carbon $carbon, $offset = 0)
{
return gmdate('D, d M Y H:i:s', $carbon->addHours($offset)->getTimestamp()) . ' GMT';
}
示例7: each
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
echo "Is yesterday? " . ($dtBerlin->isYesterday() ? "yes" : "no") . PHP_EOL;
echo "Is a Thursday? " . ($dtBerlin->isThursday() ? "yes" : "no") . PHP_EOL;
echo "Is in the future? " . ($dtBerlin->isFuture() ? "yes" : "no") . PHP_EOL;
echo "Is a leap year? " . ($dtBerlin->isLeapYear() ? "yes" : "no") . PHP_EOL;
// first and last of the month
echo "First of the month " . $dtBerlin->firstOfMonth() . PHP_EOL;
echo "Last of the month " . $dtBerlin->lastOfMonth() . PHP_EOL;
// nthOf* function test
echo "Start of the month ", $dtBerlin->startOfMonth() . PHP_EOL;
echo "End of the month ", $dtBerlin->endOfMonth() . PHP_EOL;
echo "End of the decade ", $dtBerlin->endOfDecade() . PHP_EOL;
// Date manipulation
echo $dtBerlin->addHours(5)->addDays(2)->addWeeks(1)->addMonths(3) . PHP_EOL;
echo $dtBerlin->subMonths(8)->subHours(7) . PHP_EOL;
// Find UK Bank Holidays
$dtLondon = CitcoCarbon::today('Europe/London');
list($date, $name) = each($dtLondon->nextBankHoliday());
printf("The next bank holiday is %s on %s\n", $name, $date);
foreach ($dtLondon->getBankHolidays([2016, 2017]) as $date => $name) {
printf("The next bank holiday is %s on %s\n", $name, $date);
}
// Find end of the current financial year
$fyCalculator = new Calculator(7, 1);
/* FY starts on July 1 */
print $fyCalculator->get($dtBerlin);
示例8: calculateNotBeforeTime
/**
*
* @param Item $item
* @param Carbon $notBeforeTime
* @return Carbon
*/
private function calculateNotBeforeTime(Item $item, Carbon $notBeforeTime)
{
switch ($item->recurring_unit) {
case "minute":
$notBeforeTime->addMinutes($item->recurring_frequency);
break;
case "hour":
$notBeforeTime->addHours($item->recurring_frequency);
break;
case "day":
$notBeforeTime->addDays($item->recurring_frequency);
break;
case "week":
$notBeforeTime->addWeeks($item->recurring_frequency);
break;
case "month":
$notBeforeTime->addMonths($item->recurring_frequency);
break;
case "year":
$notBeforeTime->addYears($item->recurring_frequency);
break;
}
return $notBeforeTime;
}
示例9: createNewToken
/**
* @param $type
* @param $value
* @param int $expires
* @return bool|Token
*/
public function createNewToken($type, $value, $expires = 2)
{
if ($this->validate($type)) {
$token = new Token();
$token->type = $type;
$token->value = $this->hash($value);
$token->expires_at = $this->carbon->addHours($expires);
return $token->save() ? $token : false;
}
return false;
}