/** * Return all date in weeks for a month. * * @param Carbon $date The month. * @param integer $firstDayOfWeek The first day of the week. * * @return Array Array of dates. */ public static function getDatesInWeeksForMonth(Carbon $date, $firstDayOfWeek) { Log::info('Get all dates in weeks for month.', compact('date', 'firstDayOfWeek')); $days = array(); $date = $date->copy(); $date->day = 1; // Get next month. $nextMonth; if ($date->month === 12) { $nextMonth = 1; } else { $nextMonth = $date->month + 1; } // Get first day of the first week. if ($date->dayOfWeek > $firstDayOfWeek) { $date->day = -($date->dayOfWeek - $firstDayOfWeek - 1); } else { if ($date->dayOfWeek < $firstDayOfWeek) { $date->day = -(6 - ($firstDayOfWeek - $date->dayOfWeek)); } } // Get rest of the days in weeks until next month and before first day of week. while (!($date->month === $nextMonth && $date->dayOfWeek === $firstDayOfWeek)) { $days[] = Carbon::createFromDate($date->year, $date->month, $date->day); $date->day++; } return $days; }
public function showCalendar($year, $month) { $date = Carbon::createFromDate($year, $month, 1); $data = $this->getCommonData(); $data['month'] = $date; $data['months'] = DateService::getMonths($date); $data['days'] = DateService::getDatesInWeeksForMonth($date, Carbon::MONDAY); return View::make('home', $data); }
public function createUsersPlayersTest($nbPlayer = 2) { // Set Php Time Out ini_set('max_execution_time', 300); //300 seconds = 5 minutes // Suppression des Users & Players de Test $deletedUsers = User::where('email', 'LIKE', '%aa.be')->delete(); // Boucle $createdUsers = 0; $messageRetour = ''; for ($u = 1; $u <= $nbPlayer; $u++) { // 1-Auto Values $autoNom = 'Player-' . $u; $autoPrenom = 'player ' . $u; $autoMail = 'player_' . $u . '@aa.be'; // 2-Create User with role = Player (3) $user = new User(); $user->email = $autoMail; $user->password = '******'; $user->username = $autoNom; $user->password_confirmation = '1111'; $user->confirmation_code = md5(uniqid(mt_rand(), true)); $user->confirmed = 1; if (!$user->save()) { $messageRetour .= 'Unable to create user ' . $user->email; $messageRetour .= print_r($user->errors()); $messageRetour .= '<hr>'; } else { $messageRetour .= $u . ' Created user ' . $user->email; $messageRetour .= '<hr>'; $userRole = DB::table('roles')->where('name', '=', 'Player')->pluck('id'); $user->roles()->attach($userRole); // 3-Create Player $userId = $user->id; $autoNation = rand(2, 4); $autoHcp = rand(0, 360) / 10; $autoLangue = rand(1, 3); $autoClub = rand(2, 7); $autosexe = rand(1, 2); $autoLicence = 'TEST' . $u; $year = rand(1950, 2006); $month = rand(1, 12); $day = rand(1, 28); Player::create(array('user_id' => $userId, 'nom' => $autoNom, 'prenom' => $autoPrenom, 'nation_id' => $autoNation, 'hcp' => $autoHcp, 'langue_id' => $autoLangue, 'club_id' => $autoClub, 'statusplayer_id' => 1, 'sexe_id' => $autosexe, 'naissance' => Carbon::createFromDate($year, $month, $day), 'licence' => $autoLicence)); $createdUsers++; } } return $messageRetour; }
/** * Get a timeline from the first to the last message * * @param \Channel $channel * * @return array */ public static function getTimeLine(\Channel $channel) { $timeline = []; // Fetch start and end time $firstMsg = \Message::where('channel', $channel->sid)->orderBy('ts', 'asc')->first(); $lastMsg = \Message::where('channel', $channel->sid)->orderBy('ts', 'desc')->first(); $firstDate = $firstMsg->getCarbon()->format('Y-m-d'); $lastDate = $lastMsg->getCarbon()->format('Y-m-d'); // Loop and add to timeline while (strtotime($firstDate) <= strtotime($lastDate)) { list($year, $month, $day) = explode('-', $firstDate); $timeline[$year][$month][$day] = \Carbon::createFromDate($year, $month, $day); $firstDate = date('Y-m-d', strtotime("+1 day", strtotime($firstDate))); } return $timeline; }
function setPricing() { $pricing = array(); $pricing['daily'] = $this->property->_est_rent_daily_price; $daily = $this->property->_est_rent_daily_price; $weekly = $this->property->_est_rent_weekly_price; $pricing['weekly'] = empty($weekly) ? $daily : $weekly / 7; $monthly = $this->property->_est_rent_monthly_price; $pricing['monthly'] = empty($monthly) ? $daily : $monthly / 30; $current = Carbon::createFromDate(2012, 1, 1); $end = Carbon::createFromDate(2013, 1, 1); $price_table = array(); $seasonal_dates = !empty($this->seasonal_pricing) ? array_keys($this->seasonal_pricing) : array(); while ($current->lt($end)) { $date = $current->format('m-d'); if (!in_array($date, $seasonal_dates)) { $price_table[$date] = $pricing; } else { $price_table[$date] = $this->seasonal_pricing[$date]; } $current->addDay(); } $this->pricing = $price_table; }
public static function prettyDate($fecha) { $this->attributes['fecha'] = Carbon::createFromDate('d-m-Y', $fecha); }