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; }
/** * 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'); } }
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); }
/** * 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 ''; } }
/** * @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'); }); }
/** * 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; }
/** * @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'); }
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'); } }
/** * 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')); } }
/** * 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]); } } }
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); }
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); }
/** * Does a charge already exist for the user and date * @param $userId * @param Carbon $date * @return bool */ public function chargeExists($userId, $date) { if ($this->model->where('user_id', $userId)->where('charge_date', $date->format('Y-m-d'))->count() !== 0) { return true; } return false; }
/** * 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'); }
public function index($day, $month) { $workday = new Carbon($day . " " . $month); $datum = $workday->format('l jS \\of F Y'); $data = array('datum' => $datum); return View('workday')->with($data); }
private function aggregateDailyLogs(Carbon $fr, Carbon $to, $branchid) { return $this->scopeQuery(function ($query) use($fr, $to, $branchid) { return $query->select(DB::raw('*, count(*) as count'))->whereBetween('filedate', [$fr->format('Y-m-d') . ' 00:00:00', $to->format('Y-m-d') . ' 23:59:59'])->where('branchid', $branchid)->groupBy(DB::raw('DAY(filedate)'))->orderBy('uploaddate', 'DESC'); //->orderBy('filedate', 'DESC'); })->all(); }
/** * __invoke * * Summaries for methods should use 3rd person declarative rather * than 2nd person imperative, beginning with a verb phrase. * * @param mixed $date DESCRIPTION * @param mixed $attr DESCRIPTION * @param mixed $format DESCRIPTION * * @return mixed * * @access public */ public function __invoke($date, $attr = [], $format = null) { $date = new Carbon($date); $attr = array_merge_recursive($attr, ['datetime' => $date->toIso8601String()]); $content = $format ? $date->format($format) : $date->toDayDateTimeString(); return parent::__invoke($content, $attr, $this->tag); }
/** * @param null|Carbon $date * @return null|string */ protected function normalizeDateTime($date) { if (!$date) { return null; } return $date->format('Y-m-d H:i'); }
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); }
public function updateBudgetPrediction($event) { $event->name = Crypt::decrypt($event->name); // remove all budget prediction points, if any $event->budgetpredictionpoints()->delete(); $similar = array(); // get all similar budgets from the past: $budgets = Auth::user()->budgets()->where('date', '<=', $event->date)->get(); foreach ($budgets as $budget) { $budget->name = Crypt::decrypt($budget->name); if ($budget->name == $event->name) { $similar[] = $budget->id; } } if (count($similar) > 0) { // get all transactions for these budgets: $amounts = array(); $transactions = Auth::user()->transactions()->orderBy('date', 'DESC')->where('onetime', '=', 0)->whereIn('budget_id', $similar)->get(); foreach ($transactions as $t) { $date = new Carbon($t->date); $day = intval($date->format('d')); $amounts[$day] = isset($amounts[$day]) ? $amounts[$day] + floatval($t->amount) * -1 : floatval($t->amount) * -1; } // then make sure it's "average". foreach ($amounts as $day => $amount) { // save as budget prediction point. $bpp = new Budgetpredictionpoint(); $bpp->budget_id = $event->id; $bpp->amount = $amount / count($similar); $bpp->day = $day; $bpp->save(); } } }
public function showAll() { $key = cacheKey('Budgets', 'showAll'); if (Cache::has($key)) { $data = Cache::get($key); } else { $data = array(); $budgets = Auth::user()->budgets()->orderBy('date', 'DESC')->get(); foreach ($budgets as $b) { $month = new Carbon($b->date); $strMonth = $month->format('F Y'); $data[$strMonth] = isset($data[$strMonth]) ? $data[$strMonth] : array(); $budget = array('name' => Crypt::decrypt($b->name), 'amount' => floatval($b->amount), 'spent' => $b->spent(), 'overspent' => false, 'id' => intval($b->id), 'left' => 0); if ($budget['amount'] != 0) { $pct = $budget['spent'] / $budget['amount'] * 100; $budget['left'] = $budget['amount'] - $budget['spent']; if ($pct > 100) { $budget['overspent'] = true; $budget['pct'] = round($budget['amount'] / $budget['spent'] * 100, 0); } else { $budget['pct'] = round($pct); } } $data[$strMonth][] = $budget; } } return View::make('budgets.all')->with('budgets', $data); }
public static function display($dateTime, $format = 'long') { if (!is_a($dateTime, Carbon::class)) { $dateTime = new Carbon($dateTime); } return $dateTime->format(config('coaster::date.format.' . $format)); }
/** * @param Carbon|null $date * @return mixed */ public function getDaysWithoutFullHours($date = null) { $query = DB::table(self::TABLE)->select(DB::raw('SUM(time) AS hours'), DB::raw('8 - SUM(TIME) AS hoursPending'), 'date')->groupBy('date'); if ($date) { $query->where('date', '>=', $date->format('Y-m-d')); } return $query->get(); }
/** * Determine if the provided expression refers to this week * * @return bool */ public function thisWeek() { $scheduleWeek = $this->scheduler->getScheduleWeek(); $currentWeek = $this->now->format('W'); //if a month is defined, week refers to the week of the month $scheduleMonth = $this->scheduler->getScheduleMonth(); if (!is_null($scheduleMonth) && $scheduleMonth !== Scheduler::NONE) { return $this->isCurrent($scheduleWeek, $this->now->weekOfMonth); } //if it's an odd or even week if ($scheduleWeek == 'odd' && $currentWeek & 1) { return true; } elseif ($scheduleWeek == 'even' && !($currentWeek & 1)) { return true; } return $this->isCurrent($scheduleWeek, $this->now->weekOfYear); }
/** * */ private function runRecordStats(Schedule $schedule, Carbon $now) { $logdir = storage_path("logs/recordstats"); if (!File::exists($logdir)) { File::makeDirectory($logdir); } $schedule->command('recordstats')->hourly()->sendOutputTo("{$logdir}/{$now->format('Y-m-d_H')}.txt.txt"); }
public function getLastCheckedAttribute($value) { if (is_null($value)) { return $value; } $date = new Carbon($value); return $date->format('d/m/y'); }
/** * * @param $date * @param $for * @return string */ function convertDate(Carbon $date, $for = NULL) { switch ($for) { case "sql": return $date->format('Y-m-d'); break; default: return $date->format('d/m/y'); break; } // if ($for === 'user') { // return $date->format('d/m/y'); // } // elseif ($for === 'sql') { // return $date->format('Y-m-d'); // // } }
public function getProfilingDateAttribute($value) { $r = null; if ($value) { $value = new Carbon($value); $r = $value->format('m/d/Y'); } return $r; }
/** * @param Carbon $date * @return $this */ public function only(Carbon $date) { $schedules = $this->filter(function (Schedule $schedule) use($date) { $entryValue = intval($schedule->getEntry()->format(self::DATE_FORMAT)); $dateValue = intval($date->format(self::DATE_FORMAT)); return $entryValue - $dateValue === 0; })->orderByEntry(); return $schedules; }
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); }