本文整理汇总了PHP中Carbon\Carbon::setTime方法的典型用法代码示例。如果您正苦于以下问题:PHP Carbon::setTime方法的具体用法?PHP Carbon::setTime怎么用?PHP Carbon::setTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carbon\Carbon
的用法示例。
在下文中一共展示了Carbon::setTime方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getExtend
public function getExtend($uid, $period)
{
/* @var $user User */
$user = User::find($uid);
if (empty($user->announcement_stream)) {
Flash::error('Пользователь не подписан на рассылку.');
return Redirect::to('admin/subscriptions');
}
// Already has an active subscription.
if ($user->announcement_expires && $user->announcement_expires->isFuture()) {
$user->announcement_expires = $user->announcement_expires->addDays($period);
}
// Subscription expired.
if ($user->announcement_expires && $user->announcement_expires->isPast()) {
// Start tomorrow.
$start = new Carbon();
$start->setTime(0, 0, 0)->addDays(1);
$user->announcement_start = $start;
// Expire in $period from tomorrow.
$expires = clone $start;
$expires->addDays($period);
$user->announcement_expires = $expires;
}
$user->save();
Flash::success('Подписка продленна.');
return Redirect::to('admin/subscriptions');
}
示例2: store
public function store()
{
$id = $this->request->input('id');
$input = $this->request->only(['provider', 'text', 'link', 'image']);
$categories = $this->request->input('categories');
$inputSchedule = $this->request->only(['schedule_date', 'schedule_time']);
if ($input['provider'] == 'weblink' && !$input['link']) {
throw new Exception('The "link" argument is missing', 1);
}
$post = (int) $id ? Post::find($id)->fill($input) : new Post($input);
if ($inputSchedule['schedule_date']) {
$time = explode(':', $inputSchedule['schedule_time']);
$date = new Carbon($inputSchedule['schedule_date']);
if (count($time) > 1) {
$date->setTime($time[0], $time[1]);
}
if ($date->timestamp > time()) {
$post->posted_at = $date;
}
} else {
$post->posted_at = new Carbon();
}
$post->user_id = $this->auth->id();
$post->save();
if (count($categories)) {
$post->categories()->sync($categories);
} else {
$post->categories()->detach();
}
$post->provider_id = $post->id;
$success = $post->save();
$job = (new PublishPost($post))->onQueue('publish');
$queued = $this->dispatch($job);
return compact('success', 'queued');
}
示例3: getUsers
protected function getUsers($days)
{
$expires = new Carbon();
$expires->setTime(0, 0, 0)->addDays($days);
$expires = $expires->format('Y-m-d H:i:s');
$users = User::where('announcement_expires', '=', $expires)->get();
return $users;
}
示例4: getFirstDate
/**
*
* Returns date (Carbon object) set to the date of the very first post
* or to current date if there are no posts
*
* @return Carbon
*/
protected static function getFirstDate()
{
$post = BlogPost::orderBy('published_at', 'asc')->isPublished()->first();
if (!$post) {
$date = new Carbon();
} else {
$date = new Carbon($post->published_at);
}
$date->setTime(0, 0);
return $date;
}
示例5: get
/**
* Get the FY end date
*
* @param Carbon $dt Date to determine FY for
*
* @return Carbon Carbon instance set to the end of the FY for the input
*/
public function get(Carbon $dt = NULL)
{
if (!$dt) {
$dt = new Carbon();
}
/* Disregard times */
$dt->setTime(0, 0, 0);
/* FY is based on the -end- of the FY, thus we will work backward to determine if we need to 'rollup' the FY
from the input year */
$fyStart = Carbon::create($dt->year, $this->month, $this->day, 0, 0, 0);
$fyEnd = clone $fyStart;
$fyEnd->addYear()->subDay();
if (!$dt->between($fyStart, $fyEnd, TRUE)) {
$fyEnd->year($dt->year);
}
return $fyEnd;
}
示例6: getCurrentRange
/**
*
* Returns with start and end dates limiting current archive output
*
* @return Carbon[] - [start, end]
*/
protected function getCurrentRange()
{
if (!$this->year) {
return [];
}
$start = new Carbon();
$end = new Carbon();
if (!$this->month) {
//year archive
$start->setDate($this->year, 1, 1);
$end->setDate(intval($this->year) + 1, 1, 1);
} else {
if (!$this->day) {
//month archive
$start->setDate($this->year, $this->month, 1);
$end->setDate($this->year, intval($this->month) + 1, 1);
} else {
//day archive
$start->setDate($this->year, $this->month, $this->day);
$end->setDate($this->year, $this->month, intval($this->day) + 1);
}
}
$start->setTime(0, 0, 0);
$end->setTime(0, 0, 0);
return [$start, $end];
}
示例7: getLatestEnd
/**
* Get the latest end time for an event on a particular day.
* @param \Carbon\Carbon $date
* @return string
*/
public function getLatestEnd(Carbon $date)
{
$date->setTime(00, 00, 00);
foreach ($this->times as $time) {
if ($time->end->isSameDay($date) && $time->end->gt($date)) {
$date->setTime($time->end->hour, $time->end->minute, $time->end->second);
}
}
return $date->format('H:i');
}
示例8: addExclusion
/**
* Add a date to exclude as a business day
*
* @param $exclusion string|Carbon
*/
public function addExclusion(Carbon $exclusion)
{
$exclusion->setTime(0, 0, 0);
$this->exclusions[] = $exclusion;
}
示例9: setupDayPager
/**
* Sets up pager to switch prev/next day
*/
protected function setupDayPager()
{
$first_date = $this->first_date;
$current_date = $this->current_date;
// previous
if ($first_date->getTimestamp() < $current_date->getTimestamp()) {
$previous_date = $current_date->copy();
$previous_date->subDay(1);
$this->previous_text = $previous_date->formatLocalized('%d') . ' ' . $previous_date->formatLocalized('%B') . ', ' . $previous_date->year;
$this->previous_url = $this->makePagerUrl(array('year' => $previous_date->year, 'month' => $previous_date->month, 'day' => $previous_date->day));
} else {
$this->previous_text = $current_date->formatLocalized('%d') . ' ' . $current_date->formatLocalized('%B') . ', ' . $current_date->year;
$this->previous_url = '';
}
// next
$today = new Carbon();
$today->setTime(0, 0);
if ($this->current_date->getTimestamp() < $today->getTimestamp()) {
$next_date = $current_date->copy();
$next_date->addDay(1);
$this->next_text = $next_date->formatLocalized('%d') . ' ' . $next_date->formatLocalized('%B') . ', ' . $next_date->year;
$this->next_url = $this->makePagerUrl(array('year' => $next_date->year, 'month' => $next_date->month, 'day' => $next_date->day));
} else {
$this->next_text = $current_date->formatLocalized('%d') . ' ' . $current_date->formatLocalized('%B') . ', ' . $current_date->year;
$this->next_url = '';
}
}
示例10: findUsersByCreatedDate
public function findUsersByCreatedDate(Carbon $fromDate, Carbon $toDate, $userType)
{
$toDate->setTime(23, 59);
$isEmpty = $userType == 'agent' ? '<>' : '=';
return User::with('country')->whereBetween('created_at', [$fromDate, $toDate])->where('agency', $isEmpty, '')->get();
}