本文整理汇总了PHP中Carbon\Carbon::format方法的典型用法代码示例。如果您正苦于以下问题:PHP Carbon::format方法的具体用法?PHP Carbon::format怎么用?PHP Carbon::format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carbon\Carbon
的用法示例。
在下文中一共展示了Carbon::format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCheckIn
public function testCheckIn()
{
$json = '{
"watched_at": "2014-08-06T01:11:37.953Z",
"sharing": {
"facebook": true,
"twitter": true,
"tumblr": false
},
"movie": {
"title": "Guardians of the Galaxy",
"year": 2014,
"ids": {
"trakt": 28,
"slug": "guardians-of-the-galaxy-2014",
"imdb": "tt2015381",
"tmdb": 118340
}
}
}';
$client = Mockery::mock(stdClass::class . ", " . ClientInterface::class);
$request = Mockery::mock(stdClass::class . ", " . RequestInterface::class);
$response = Mockery::mock(stdClass::class . ", " . ResponseInterface::class);
$client->shouldReceive("createRequest")->once()->andReturn($request);
$response->shouldReceive("getStatusCode")->once()->andReturn(200);
$response->shouldReceive("json")->once()->andReturn(json_decode($json));
$client->shouldReceive("send")->once()->andReturn($response);
$auth = mock_auth();
$trakt = new Trakt($auth, $client);
$checkIn = $trakt->checkIn;
$this->assertInstanceOf("Wubs\\Trakt\\Api\\CheckIn", $checkIn);
$response = $checkIn->create(get_token(), movie($client), "nooo way!", ['facebook' => false, 'twitter' => false, 'tumblr' => false], "1200", "blablabla", "1.1", $this->today->format("Y-m-d"));
$this->assertInstanceOf("Wubs\\Trakt\\Response\\CheckIn", $response);
}
示例2: getDepartures
/**
* Gets departures from the given station starting at the given time.
*
* @param int $stationID
* @param Carbon $time
* @return array
* @throws ApiException
*/
public static function getDepartures(int $stationID, Carbon $time, int $maxJourneys = 10)
{
// prepare parameters for our request
$query = ['input' => $stationID, 'boardType' => 'dep', 'time' => $time->format('H:i'), 'date' => $time->format('d.m.y'), 'maxJourneys' => $maxJourneys, 'start' => 'yes'];
// send it to the bvg mobile site
$response = \Requests::get(self::getApiEndpoint() . '?' . http_build_query($query));
if ($response->status_code == 200) {
// our results array
$departures = [];
// prepare document
$dom = new Dom();
$dom->load($response->body);
// get date from API
$date = $dom->find('#ivu_overview_input');
$date = trim(substr($date->text, strpos($date->text, ':') + 1));
$date = Carbon::createFromFormat('d.m.y', $date, 'Europe/Berlin');
// get table data without the first line (header)
$rows = $dom->find('.ivu_result_box .ivu_table tbody tr');
// loop through each departure in the table
foreach ($rows as $row) {
// get columns
$columns = $row->find('td');
// explode time into two parts
$time = explode(':', strip_tags($columns[0]));
// push the departure onto our results array
$departures[] = ['time' => $date->copy()->hour($time[0])->minute($time[1])->second(0), 'line' => trim(strip_tags($columns[1]->find('a')[0])), 'direction' => trim(strip_tags($columns[2]))];
}
// return results
return $departures;
} else {
throw new ApiException('Failed getting station data from BVG API');
}
}
示例3: generate
public function generate($employeeid, Carbon $date, $timelogs)
{
$this->timelogs = $timelogs;
$this->workHours = Carbon::parse($date->format('Y-m-d') . ' 00:00:00');
$this->otHours = Carbon::parse($date->format('Y-m-d') . ' 00:00:00');
for ($i = 1; $i < 5; $i++) {
$log = $timelogs->where('employeeid', $employeeid)->where('txncode', $i)->sortBy('datetime')->first();
if (!is_null($log)) {
switch ($i) {
case 1:
$this->timein = new Log($log);
break;
case 2:
$this->breakin = new Log($log);
break;
case 3:
$this->breakout = new Log($log);
break;
case 4:
$this->timeout = new Log($log);
break;
}
}
}
$this->checkBreak();
$this->computeWorkHours();
return $this;
}
示例4: getValue
/**
* Get this date as a string.
*
* Empty string if no date is set.
*
* @return string
*/
public function getValue()
{
if ($this->date) {
return $this->date->format($this->format);
} else {
return '';
}
}
示例5: scopeRelevantOnDate
/**
* @param EloquentBuilder $query
* @param Carbon $date
*
* @return mixed
*/
public function scopeRelevantOnDate(EloquentBuilder $query, Carbon $date)
{
return $query->where(function (EloquentBuilder $q) use($date) {
$q->where('startdate', '<=', $date->format('Y-m-d 00:00:00'));
$q->orWhereNull('startdate');
})->where(function (EloquentBuilder $q) use($date) {
$q->where('targetdate', '>=', $date->format('Y-m-d 00:00:00'));
$q->orWhereNull('targetdate');
});
}
示例6: store
/**
* Store the compiled stub.
*
* @param $modelName
* @param \stdClass $scaffolderConfig
* @param $compiled
* @param \Scaffolder\Support\FileToCompile $fileToCompile
*
* @return string
*/
protected function store($modelName, stdClass $scaffolderConfig, $compiled, FileToCompile $fileToCompile)
{
$path = PathParser::parse($scaffolderConfig->paths->migrations) . $this->date->format('Y_m_d_His') . '_create_' . strtolower($modelName) . 's_table.php';
// Store in cache
if ($fileToCompile->cached) {
File::copy(base_path('scaffolder-config/cache/migration_' . $fileToCompile->hash . self::CACHE_EXT), $path);
} else {
File::put(base_path('scaffolder-config/cache/migration_' . $fileToCompile->hash . self::CACHE_EXT), $compiled);
File::copy(base_path('scaffolder-config/cache/migration_' . $fileToCompile->hash . self::CACHE_EXT), $path);
}
return $path;
}
示例7: displayRange
/**
* @param Carbon $start
* @param Carbon $end
*/
public static function displayRange(Carbon $start, Carbon $end)
{
if ($start->eq($end)) {
return $end->format('F j, Y');
}
if ($start->year != $end->year) {
return $start->format('F j, Y') . ' - ' . $end->format('F j, Y');
}
if ($start->month != $end->month) {
return $start->format('F j') . ' - ' . $end->format('F j, Y');
}
return $start->format('F j') . ' - ' . $end->format('j, Y');
}
示例8: formatHistory
public static function formatHistory($val)
{
$time = new Carbon($val);
$now = Carbon::now();
if ($time->isToday() == $now->isToday()) {
return 'Today at ' . $val->format('H:i');
} elseif ($time->isYesterday()) {
return 'Yesterday at ' . $val->format('H:i');
} elseif ($time->format('Y') == $now->format('Y')) {
return $val->format('d M, H:i');
} elseif ($time->format('Y') != $now->format('Y')) {
return $val->format('d M Y, H:i');
}
}
示例9: index
/**
* Display a listing of tarefas
*
* @return Response
*/
public function index()
{
$data = Input::get();
$data['view'] = Input::has('view') ? Input::get('view') : 'today';
// today, late, next, done
$data['paginate'] = Input::has('paginate') ? Input::get('paginate') : 10;
$dt = new Carbon();
$tarefas = Tarefa::where(function ($query) use($data, $dt) {
switch ($data['view']) {
case 'late':
$query->where('date', '<', $dt->format('Y-m-d'))->where('done', false);
break;
case 'next':
$query->where('date', '>', $dt->format('Y-m-d'))->where('done', false);
break;
case 'done':
$query->where('done', true);
break;
default:
// TODAY
$query->where('date', '>=', $dt->startOfDay()->format('Y-m-d'))->where('date', '<=', $dt->endOfDay()->format('Y-m-d'));
break;
}
})->orderBy(Input::get('order_by', 'date'), Input::get('order', 'DESC'))->with('cliente', 'conversas')->paginate(Input::get('paginate', 10));
// $tarefas = Tarefa::orderBy('date', 'DESC')->with('cliente')->get();
$hoje = date('Y-m-d');
$ontem = Carbon::create(date('Y'), date('m'), date('d'))->subDay();
$amanha = Carbon::create(date('Y'), date('m'), date('d'))->addDay();
$proximo = Carbon::create(date('Y'), date('m'), date('d'))->addDay();
//Igual amanhã?
if ($proximo->isWeekend()) {
$proximo = new Carbon('next monday');
}
$tarefas->pendentes = Tarefa::where('date', '<', $hoje)->where('done', 0)->orderBy('date', 'ASC')->with('cliente', 'conversas')->get();
$tarefas->hoje = Tarefa::where('date', '<', $amanha->startOfDay())->where('date', '>', $ontem)->where('done', 0)->with('cliente', 'conversas')->get();
$tarefas->nextDay = Tarefa::where('done', 0)->where('date', '>=', $amanha)->where('date', '<', $proximo->addDay())->orderBy('date', 'DESC')->with('cliente', 'conversas')->get();
$tarefas->proximas = Tarefa::where('date', '>=', $amanha)->orderBy('date', 'ASC')->where('done', 0)->with('cliente', 'conversas')->get();
$tarefas->concluidas = Tarefa::where('done', 1)->orderBy('updated_at', 'DESC')->with('cliente', 'conversas')->get();
$tarefas->days = $tarefas->groupBy(function ($tarefa) {
return date('Y-m-d', strtotime($tarefa->date));
});
if (Request::ajax()) {
return $tarefas;
}
if (Route::is('tarefas.print')) {
return View::make('tarefas.print', compact('tarefas'));
} else {
return View::make('tarefas.index', compact('tarefas'));
}
}
示例10: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$studentCursorSql = "SELECT s. ID, uffr1.CREATED_BY FROM students s " . "JOIN U_FB_FORM_RESPONSE uffr1 ON (uffr1.STUDENT_ID = s.ID) LEFT OUTER " . "JOIN U_FB_FORM_RESPONSE uffr2 ON (s.id = uffr2.STUDENT_ID AND " . "(uffr1.CREATED_ON < uffr2.CREATED_ON OR uffr1.CREATED_ON = " . "uffr2.CREATED_ON AND uffr1.id < uffr2.id)) LEFT JOIN U_FB_FORM uff ON " . "uff.ID = uffr1.U_FB_FORM_ID WHERE uffr2.ID IS NULL AND uff.FORM_TITLE LIKE 'IEP%'";
$studentCursor = DB::connection('oracle')->select($studentCursorSql);
foreach ($studentCursor as $student) {
$formCursorSql = "SELECT U_FB_FORM_RESPONSE. ID, U_FB_FORM.FORM_TITLE " . "FROM U_FB_FORM_RESPONSE JOIN u_fb_form ON U_FB_FORM. ID = " . "U_FB_FORM_RESPONSE.U_FB_FORM_ID WHERE U_FB_FORM.FORM_TITLE LIKE " . "'IEP%' AND U_FB_FORM_RESPONSE.STUDENT_ID = ?";
$formCursor = DB::connection('oracle')->select($formCursorSql, [$student->id]);
$date = new Carbon('now');
$lastInsertedId = DB::table('iep')->insertGetId(['student_id' => $student->id, 'case_manager' => $student->created_by, 'is_active' => true, 'created_at' => $date->format('y/m/d/ H:i:s'), 'updated_at' => $date->format('y/m/d/ H:i:s')]);
foreach ($formCursor as $formRecord) {
DB::table('iep_responses')->insert(['iep_id' => $lastInsertedId, 'response_id' => $formRecord->id]);
}
}
}
示例11: export
private function export($data, Carbon $date, $ext = 'xlsx')
{
$ext = in_array($ext, ['xls', 'xlsx', 'csv']) ? $ext : 'xlsx';
$filename = 'PO-' . session('user.branchcode') . '-' . $date->format('Ymd') . '-' . Carbon::now()->format('His');
$output = [];
array_push($output, ['Component', 'Category', 'UoM', 'Qty', 'Unit Cost', 'Total Cost', 'Sup Code', 'Sup Name', 'Terms', 'VAT']);
foreach ($data as $d) {
array_push($output, [$d->comp, $d->catname, $d->unit, $d->qty, $d->ucost, $d->tcost, $d->supno, $d->supname, $d->terms, $d->vat]);
}
return Excel::create($filename, function ($excel) use($output, $date) {
$excel->sheet('PO-' . $date->format('Y-m-d'), function ($sheet) use($output) {
$sheet->fromArray($output, null, 'A1', false, false);
});
})->export($ext);
}
示例12: startDateCannotBeAfterEndDate
public static function startDateCannotBeAfterEndDate(Carbon $startDate, Carbon $endDate)
{
$startDateFormatted = $startDate->format('d-m-Y');
$endDateFormatted = $endDate->format('d-m-Y');
$message = "Start date `{$startDateFormatted}` cannot be after end date `{$endDateFormatted}`.";
return new self($message);
}
示例13: showAll
public function showAll()
{
$key = cacheKey('Beneficiaries', 'showAll');
if (Cache::has($key)) {
$data = Cache::get($key);
} else {
$data = array();
$beneficiaries = Auth::user()->beneficiaries()->orderBy('id', 'ASC')->get();
// to get the avg per month we first need the number of months
foreach ($beneficiaries as $ben) {
$name = Crypt::decrypt($ben->name);
$bene = array('id' => intval($ben->id), 'name' => $name);
$now = new Carbon('now');
$thisMonth = $ben->transactions()->where(DB::Raw('DATE_FORMAT(`date`,"%m-%Y")'), '=', $now->format('m-Y'))->sum('amount');
$bene['month'] = floatval($thisMonth);
$data[] = $bene;
}
unset($name);
$name = array();
// order by alfabet
// Obtain a list of columns
foreach ($data as $key => $row) {
$id[$key] = $row['id'];
$name[$key] = $row['name'];
}
array_multisort($name, SORT_ASC, $id, SORT_DESC, $data);
Cache::put($key, $data, 1440);
}
return View::make('beneficiaries.all')->with('beneficiaries', $data);
}
示例14: foreach
function update_episodes($parent_id, $rss)
{
foreach ($rss->channel->item as $item) {
if (!$item->enclosure) {
continue;
}
$enclosure = $item->enclosure->attributes();
$pubDate = new Carbon($item->pubDate->__toString());
$arr = array('parent_id' => $parent_id, 'title' => $this->sanitize($item->title->__toString()), 'pubDate' => $pubDate->format('U'), 'guid' => $item->guid->__toString(), 'link' => $item->link->__toString(), 'description' => $this->sanitize($item->description->__toString()), 'enclosure' => array('length' => $enclosure['length']->__toString(), 'type' => $enclosure['type']->__toString(), 'url' => $enclosure['url']->__toString()), 'itunes' => array('image' => '', 'duration' => $item->children('itunes', true)->duration->__toString(), 'explicit' => $item->children('itunes', true)->explicit->__toString(), 'keywords' => $this->sanitize($item->children('itunes', true)->keywords->__toString()), 'subtitle' => $this->sanitize($item->children('itunes', true)->subtitle->__toString())), 'raw' => $item->asXml());
$node = $item->children('itunes', true)->image;
// Needed to force evaluation
if ($node) {
$itunes_image = $node->attributes();
$arr['itunes']['image'] = $itunes_image['href']->__toString();
}
$items[] = $arr;
}
usort($items, function ($a, $b) {
if ($a['pubDate'] == $b['pubDate']) {
return 0;
}
if ($a['pubDate'] < $b['pubDate']) {
return 1;
}
return -1;
});
$items = array_slice($items, 0, RECAST_EPISODE_LIMIT);
for ($i = 0; $i < count($items); $i++) {
self::process_episode($items[$i]);
}
$args = array('posts_per_page' => -1, 'offset' => 0, 'post_type' => 'episode', 'meta_key' => 'podcast_id', 'meta_value' => $parent_id);
$q = new WP_Query($args);
update_post_meta($parent_id, 'episode_count', $q->found_posts);
}
示例15: date
/**
* Default application formatter for dates
*
* @param Carbon|null $value The value to format.
*
* @return string
*/
public static function date(Carbon $value)
{
if (empty($value)) {
return '';
}
return $value->format('M n Y');
}