本文整理汇总了PHP中Carbon\Carbon::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Carbon::parse方法的具体用法?PHP Carbon::parse怎么用?PHP Carbon::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carbon\Carbon
的用法示例。
在下文中一共展示了Carbon::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: it_has_a_timezone_attribute
/**
* @test
*/
public function it_has_a_timezone_attribute()
{
$carbon = Carbon::parse('today')->addDays(7);
$appointment = $this->createAppointmentPresenter(['start_at' => $carbon, 'finish_at' => $carbon->addHours(1)]);
$appointment->setTimezone('Europe/Madrid');
$this->assertInternalType('string', $appointment->timezone());
}
示例2: buildNextWeekTag
/**
* 金曜日になると今週の週報タグを生成する
*/
public function buildNextWeekTag()
{
\Log::info('Start generate tag of This week. ');
$dt = new Carbon();
// $dt->setTestNow($dt->createFromDate(2015, 5, 31));
if ($dt->now()->dayOfWeek === Carbon::FRIDAY) {
//翌月
$nextMonth = $dt->parse('next month')->month;
// 現在が何週目か
\Log::info('今日は' . $dt->now()->month . '月の第' . $dt->now()->weekOfMonth . '週目です');
//今週の金曜を取得
$thisFriday = $dt->parse('this friday');
\Log::info('来週の金曜は' . $thisFriday);
// 月またぎの場合
if ($thisFriday->month === $nextMonth) {
\Log::info($thisFriday->year . '年の' . $thisFriday->month . '月の第' . $thisFriday->weekOfMonth . '週目です');
$nextWeekTag = '週報@' . $thisFriday->year . '年' . $thisFriday->month . '月第' . $thisFriday->weekOfMonth . '週';
$this->tag->tag = $nextWeekTag;
$this->tag->save();
} else {
\Log::info('翌週は' . $thisFriday->month . '月の第' . $thisFriday->weekOfMonth . '週目です');
$nextWeekTag = '週報@' . $thisFriday->year . '年' . $thisFriday->month . '月第' . $thisFriday->weekOfMonth . '週';
$this->tag->tag = $nextWeekTag;
$this->tag->save();
}
\Log::info('End generate tag');
} else {
\Log::info('Today is not Friday.');
}
}
示例3: handle
/**
* Handle the event.
*
* @param Event $event
* @return void
*/
public function handle(Event $event)
{
/**
* Create Voting
*/
$vote_open_date = $this->carbon->parse($event->voting_date);
$vote_close_date = $vote_open_date->copy()->addMinutes(config('defaults.project.voting_span_time'));
$this->dispatch(new CreateVotingCommand($event->model, $vote_open_date, $vote_close_date));
}
示例4: create
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create(Request $request)
{
$inquiry = DB::table('inquiries')->orderBy('stop', 'desc')->first();
$start = Carbon::parse($inquiry->stop)->format('Y-m-d');
$stop = Carbon::parse($inquiry->stop)->addWeek()->format('Y-m-d');
// echo $start;
// $inputData = $request->all();
// if ($start>$inputData['start'])
// {
// echo "start is kleiner";
// }
// echo $inputData['start'];
$this->validate($request, ['inquiry' => 'required|max:255', 'awnser' => 'required|max:255', 'option1' => 'required|max:255', 'option2' => 'required|max:255', 'option3' => 'required|max:255', 'start' => 'required|date:after:' . $start, 'stop' => 'required|date:after:' . $stop]);
$inputData = $request->all();
$inquiry = new Inquiry();
$inquiry->question = $inputData['inquiry'];
$inquiry->awnser = $inputData['awnser'];
$inquiry->option1 = $inputData['option1'];
$inquiry->option2 = $inputData['option2'];
$inquiry->option3 = $inputData['option3'];
$inquiry->start = $inputData['start'];
$inquiry->stop = $inputData['stop'];
$inquiry->save();
return redirect()->route('home');
}
示例5: __construct
public function __construct()
{
$from = Input::get('from');
$this->from = $from ? Carbon::parse($from) : null;
$to = Input::get('to');
$this->to = $to ? Carbon::parse($to) : null;
}
示例6: getDeletedAtAttribute
/**
* Formats the deleted_at timestamp.
*
* @param string $deleted_at
*
* @return string|null
*/
public function getDeletedAtAttribute($deleted_at)
{
if (array_key_exists('deleted_at', $this->attributes)) {
return Carbon::parse($deleted_at)->format('Y-m-d h:i A');
}
return null;
}
示例7: carian
public function carian()
{
$tarikh = Carbon::parse(\Input::get('tarikh'));
$bil = 1;
$laporans = Laporan::latest('tarikh')->where('tarikh', 'like', $tarikh . '%')->where('user', Auth::user()->username)->latest('tarikh')->get();
return View('members.technician.carian', compact('bil', 'laporans', 'tarikh'));
}
示例8: init
/**
* {@inheritDoc}
*/
public function init()
{
$this->fillFromConfig(['mode', 'minDate', 'maxDate']);
$this->mode = strtolower($this->mode);
$this->minDate = is_integer($this->minDate) ? Carbon::createFromTimestamp($this->minDate) : Carbon::parse($this->minDate);
$this->maxDate = is_integer($this->maxDate) ? Carbon::createFromTimestamp($this->maxDate) : Carbon::parse($this->maxDate);
}
示例9: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$client = Client::findOrFail($id);
$projects = Client::find($id)->projects()->orderBy('id', 'desc')->get();
$invoices = Client::find($id)->invoices()->orderBy('id', 'desc')->get();
$quotes = Client::find($id)->quotes()->orderBy('id', 'desc')->get();
$client->client_id = $client->id + 999;
foreach ($invoices as $invoice) {
$issue_date = Carbon::parse($invoice->issue_date);
$due_date = Carbon::parse($invoice->due_date);
$now = Carbon::now();
if ($now > $due_date) {
$invoice->is_overdue = true;
} else {
$invoice->is_overdue = false;
}
$invoice->readable_specific_id = $invoice->client_specific_id;
if ($invoice->client_specific_id < 10) {
$invoice->readable_specific_id = sprintf("%02d", $invoice->client_specific_id);
}
$invoice->terms_diff = $issue_date->diffInDays($due_date);
}
foreach ($quotes as $quote) {
if ($quote->client_specific_id < 10) {
$quote->client_specific_id = sprintf("%02d", $quote->client_specific_id);
}
}
foreach ($projects as $project) {
$project->latest_activity = $project->project_activity()->latest()->first();
}
$totalPaid = $client->invoices()->paid()->sum('amount');
$totalOutstanding = $client->invoices()->active()->sum('amount');
return view('app.client', ['client' => $client, 'projects' => $projects, 'invoices' => $invoices, 'quotes' => $quotes, "total_paid" => $totalPaid, 'total_outstanding' => $totalOutstanding]);
}
示例10: getSales
public function getSales()
{
$from = Input::get('from');
$to = Input::get('to');
$all_orders = Order::where(function ($q) use($from, $to) {
if ($from) {
$q->where('created_at', '>=', Carbon::parse($from));
}
if ($to) {
$q->where('created_at', '<=', Carbon::parse($to));
}
})->get();
$paid_orders = Order::where(function ($q) use($from, $to) {
$q->where('state', '1');
if ($from) {
$q->where('created_at', '>=', Carbon::parse($from));
}
if ($to) {
$q->where('created_at', '<=', Carbon::parse($to));
}
})->get();
$total_summ_paid_orders = 0;
foreach ($paid_orders as $order) {
$total_summ_paid_orders += $order->sum;
}
$period = ['from' => $from, 'to' => $to, 'text' => $this->period_text($from, $to)];
return view('admin.stat.sales', ['paid_orders' => $paid_orders, 'orders' => $all_orders, 'total_summ_paid_orders' => number_format($total_summ_paid_orders, 2, ',', ' '), 'period' => $period]);
}
示例11: update
/**
* Update the specified resource in storage.
*
* @param Request $request
* @return Response
* @internal param User $user
* @internal param int $id
*/
public function update(Request $request)
{
$this->validate($request, ['first_name' => 'required|max:255', 'last_name' => 'required|max:255', 'sex' => 'required', 'date_of_birth' => 'required']);
$request['date_of_birth'] = Carbon::parse($request->get('date_of_birth'));
Auth::user()->update($request->all());
return redirect(url('/users/show'))->with('message', "Successfully updated Your info.");
}
示例12: agendaJson
public function agendaJson(Request $request)
{
// load of actions between start and stop provided by calendar js
if ($request->has('start') && $request->has('end')) {
$actions = \App\Action::with('group')->where('start', '>', Carbon::parse($request->get('start')))->where('stop', '<', Carbon::parse($request->get('end')))->orderBy('start', 'asc')->get();
} else {
$actions = \App\Action::with('group')->orderBy('start', 'asc')->get();
}
$event = '';
$events = '';
foreach ($actions as $action) {
$event['id'] = $action->id;
$event['title'] = $action->name;
$event['description'] = $action->body . ' <br/> ' . $action->location;
$event['body'] = filter($action->body);
$event['summary'] = summary($action->body);
$event['location'] = $action->location;
$event['start'] = $action->start->toIso8601String();
$event['end'] = $action->stop->toIso8601String();
$event['url'] = action('ActionController@show', [$action->group->id, $action->id]);
$event['group_url'] = action('ActionController@index', [$action->group->id]);
$event['group_name'] = $action->group->name;
$event['color'] = $action->group->color();
$events[] = $event;
}
return $events;
}
示例13: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->info('Remove no longer used logs');
$difference = Carbon::parse("-1 months");
$logs = ApiLog::onlyTrashed()->where('deleted_at', '<', $difference)->latest()->forceDelete();
$this->info('Done!');
}
示例14: _remindAbout
/**
* Sends a message for an appointment
*
* @param Appointment $appointment The appointment to remind
*
* @return void
*/
private function _remindAbout($appointment)
{
$recipientName = $appointment->name;
$time = Carbon::parse($appointment->when, 'UTC')->subMinutes($appointment->timezoneOffset)->format('g:i a');
$message = "Hello {$recipientName}, this is a reminder that you have an appointment at {$time}!";
$this->_sendMessage($appointment->phoneNumber, $message);
}
示例15: groupByDateTime
public static function groupByDateTime($data, $dateFormat)
{
$data = static::toCollection($data)->groupBy(function ($date) use($dateFormat) {
return Carbon::parse($date->created_at)->format($dateFormat);
});
return static::sortByKeys($data);
}