本文整理汇总了PHP中Carbon\Carbon::createFromDate方法的典型用法代码示例。如果您正苦于以下问题:PHP Carbon::createFromDate方法的具体用法?PHP Carbon::createFromDate怎么用?PHP Carbon::createFromDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carbon\Carbon
的用法示例。
在下文中一共展示了Carbon::createFromDate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$user = \Auth::user();
$userRole = $user->hasRole('user');
$editorRole = $user->hasRole('editor');
$adminRole = $user->hasRole('administrator');
if ($userRole) {
$access = 'User';
} elseif ($editorRole) {
$access = 'Editor';
} elseif ($adminRole) {
$access = 'Administrator';
}
$today = Carbon::today();
$año = $today->year;
// int(2012)
$mes = $today->month;
$Activos = Employees::Activos()->count();
$Bajas = EstadosRevista::BajasDelMes($año, $mes)->count();
$AltasNuevas = Employees::Activos()->get()->sortBy('Fecha_Ingreso')->forPage(1, 8);
$Liquidaciones = Liquidacion::where('año', $año)->where('mes', '<=', 12)->whereNull('deleted_at')->orderBy('mes')->get();
$UltimaLiquidacion = Liquidacion::where('año', $año)->where('mes', '<=', 12)->whereNull('deleted_at')->orderBy('mes', 'desc')->first();
$AnteUltimaLiquidacion = Liquidacion::where('año', $año)->where('mes', '<=', $UltimaLiquidacion->mes)->whereNull('deleted_at')->orderBy('mes', 'desc')->first();
$Meses = $Liquidaciones->sortByDesc('mes')->lists('mes');
$Reten = $Liquidaciones->sortByDesc('mes')->lists('total_retenciones')->toArray();
$Debes = $Liquidaciones->sortByDesc('mes')->lists('total_debes')->toArray();
setlocale(LC_TIME, 'Spanish');
$MesesEsp = [];
foreach ($Meses as $MesEsp) {
$MesesEsp = array_prepend($MesesEsp, '"' . Carbon::createFromDate($año, $MesEsp, 1)->formatLocalized('%B') . '"');
}
return view('admin.pages.user-home', compact('Activos', 'Bajas', 'AltasNuevas', 'Liquidaciones', 'UltimaLiquidacion', 'AnteUltimaLiquidacion', 'MesesEsp', 'Debes', 'Reten'))->withUser($user)->withAccess($access);
}
示例2: index
public function index()
{
// create new sitemap object
$sitemap = App::make("sitemap");
// set cache key (string), duration in minutes (Carbon|Datetime|int), turn on/off (boolean)
// by default cache is disabled
$sitemap->setCache('laravel.sitemap', 60);
// check if there is cached sitemap and build new only if is not
if (!$sitemap->isCached()) {
// add item to the sitemap (url, date, priority, freq)
$sitemap->add(url('about'), Carbon::createFromDate(2016, 7, 15), '0.3', 'monthly');
$sitemap->add(url('privacy'), Carbon::createFromDate(2016, 7, 15), '0.3', 'monthly');
$sitemap->add(url('terms'), Carbon::createFromDate(2016, 7, 15), '0.3', 'monthly');
$designers = Designer::orderBy('created_at', 'desc')->get();
foreach ($designers as $designer) {
$sitemap->add($designer->url, $designer->updated_at, 0.8, 'daily');
}
$places = Place::orderBy('created_at', 'desc')->get();
foreach ($places as $place) {
$sitemap->add($place->url, $place->updated_at, 0.8, 'daily');
}
$stories = Story::orderBy('created_at', 'desc')->get();
foreach ($stories as $story) {
$sitemap->add($story->url, $story->updated_at, 0.8, 'daily');
}
$tags = Tag::orderBy('created_at', 'desc')->get();
foreach ($tags as $tag) {
$sitemap->add($tag->url, $tag->updated_at, 0.8, 'weekly');
}
}
// show your sitemap (options: 'xml' (default), 'html', 'txt', 'ror-rss', 'ror-rdf')
return $sitemap->render('xml');
}
示例3: testCopyEnsureTzIsCopied
public function testCopyEnsureTzIsCopied()
{
$dating = Carbon::createFromDate(2000, 1, 1, 'Europe/London');
$dating2 = $dating->copy();
$this->assertSame($dating->tzName, $dating2->tzName);
$this->assertSame($dating->offset, $dating2->offset);
}
示例4: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
// internally, if there's no year we will do the current year
$year = $this->argument('year') ?? date('Y');
$this->createSponsors();
/**
* @var $date Carbon
*/
$date = Carbon::createFromDate($year, 1, 1, new \DateTimeZone('Australia/Melbourne'));
do {
// events are 2nd Thursday of the month, not January
if ($date->month > 1) {
$date->nthOfMonth(2, Carbon::THURSDAY)->setTime(18, 30);
$this->createMeetupEvent($date);
}
// hack nights last Tuesday of the month
$date->lastOfMonth(Carbon::TUESDAY)->setTime(18, 30);
$this->createHackNightEvent($date);
if ($date->month > 7) {
$date->firstOfMonth(Carbon::FRIDAY)->setTime(7, 30);
if ($date->month == 11) {
$date->addDays(7);
// delayed one week in November
}
$this->createNSBreakfastEvent($date);
}
$date = $date->copy()->startOfMonth()->addMonth();
} while ((int) $date->year === (int) $year);
$this->createSpecialEvents();
}
示例5: run
public function run()
{
Astronaut::create(array('first_name' => 'Robert', 'last_name' => 'Behnken', 'gender' => 'Male', 'deceased' => false, 'nationality' => 'United States', 'date_of_birth' => Carbon::createFromDate(1970, 7, 28), 'contracted_by' => 'NASA'));
Astronaut::create(array('first_name' => 'Sunita', 'last_name' => 'Williams', 'gender' => 'Female', 'deceased' => false, 'nationality' => 'United States', 'date_of_birth' => Carbon::createFromDate(1965, 9, 19), 'contracted_by' => 'NASA'));
Astronaut::create(array('first_name' => 'Eric', 'last_name' => 'Boe', 'gender' => 'Male', 'deceased' => false, 'nationality' => 'United States', 'date_of_birth' => Carbon::createFromDate(1964, 10, 1), 'contracted_by' => 'NASA'));
Astronaut::create(array('first_name' => 'Douglas', 'last_name' => 'Hurley', 'gender' => 'Male', 'deceased' => false, 'nationality' => 'United States', 'date_of_birth' => Carbon::createFromDate(1966, 10, 21), 'contracted_by' => 'NASA'));
}
示例6: store
/**
* Store a new LaraSocial user.
*
* @return Response
*/
public function store(RegisterUserRequest $request)
{
$newUserProfileImagePath = $profileImagePath = App::make('ProcessImage')->execute($request->file('profileimage'), 'images/profileimages/', 180, 180);
$newUserBirthday = Carbon::createFromDate($request->year, $request->month, $request->day);
$newUser = $this->dispatchFrom(RegisterUserCommand::class, $request, ['birthday' => $newUserBirthday, 'profileImagePath' => $newUserProfileImagePath]);
return redirect()->route('feeds_path');
}
示例7: run
public function run()
{
DB::table('users')->delete();
$rows[] = ['id' => 1, 'name' => "admin", 'email' => "admin@example.com", 'sex' => "female", 'date_of_birth' => Carbon::createFromDate(1988, 9, 03)->toDateString(), 'role' => "user", 'password' => bcrypt("admin"), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()];
$rows[] = ['id' => 2, 'name' => "admin2", 'email' => "admin2@example.com", 'sex' => "male", 'date_of_birth' => Carbon::createFromDate(1987, 04, 22)->toDateString(), 'role' => "user", 'password' => bcrypt("admin2"), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()];
DB::table('users')->insert($rows);
}
示例8: getTraerEmp
public function getTraerEmp(Request $request)
{
$empleado = array();
$ultliq = array();
$idEmp = $request->idEmp;
$empleado = Empleado::find($idEmp);
//$empOk ['empleado'] = $empleado;
$cantFlia = GrupoFamiliar::where('grupofamiliar_idempl_foreign', '=', $idEmp)->count();
$empleado['cantFlia'] = $cantFlia;
$ultliq = Liquidacion::where('liquidacion_idempl_foreign', '=', $idEmp)->orderBy('id', 'desc')->first();
$cantLiq = Liquidacion::where('liquidacion_idempl_foreign', '=', $idEmp)->count();
$ultliq['cantLiq'] = $cantLiq;
$fecDesdeNue = $ultliq->fechaHasta;
//$fecHastaNue = $fecDesdeNue->addMonth(1);
$fecHastaNue = $ultliq->fechaHasta->addMonth(1);
$fecDesdeNue = $fecDesdeNue->format('d-m-Y');
$fecHastaNue = $fecHastaNue->format('d-m-Y');
//$date = $date->format('d-m-Y');
$anio = $empleado->fechaIngreso->year;
//1979;
$mes = $empleado->fechaIngreso->month;
//12;
$dia = $empleado->fechaIngreso->day;
//19;
$antiguedad = Carbon::createFromDate($anio, $dia, $mes)->age;
// 43
//$rol = Categoria::where('categoria_idempl_foreign', '=', $idEmp)->get();
$rol = Categoria::find($empleado->empleado_idcat_foreign);
$empleado['rol'] = $rol->nombrecat;
$empleado['Sueldo'] = $rol->sueldoBasico;
return response()->json(["msg" => "Succes", "empleadoEncontrado" => $empleado, "fecDesdeNue" => $fecDesdeNue, "fecHastaNue" => $fecHastaNue, "ultliq" => $ultliq, "antiguedad" => $antiguedad], 200);
}
示例9: display
function display($date)
{
global $ownership, $ownershipOriginal;
$week = $date->copy()->addDays(3)->format('W');
// $week = date("W", mktime(0,0,0, $date->month, $date->day+3, $date->year));
// echo $date->format('M d, Y | l |')." ";
echo "{$date->year} | {$week} | ";
echo $date->copy()->startOfWeek()->format('m/d') . ' | ' . $date->copy()->endOfWeek()->format('m/d');
echo ' | ' . $ownership->determine($date->day, $date->month, $date->year);
echo ' | (' . $ownershipOriginal->determine($date->day, $date->month, $date->year) . ')';
if ($date->isSameDay(Carbon::createFromDate($date->year, 1, 1))) {
echo " | New Years Day -> " . $date->format('m/d l');
}
if ($week == $ownership->fourthOfJulyWeek($date->year)) {
$fourth = Carbon::createFromDate($date->year, 7, 4);
echo " | July 4th Week -> " . $fourth->format('m/d l');
}
if ($week == $ownership->memorialDayWeek($date->year)) {
echo " | Memorial Day Week -> " . $date->copy()->lastOfMonth(Carbon::MONDAY)->format('m/d l');
}
if ($week == $ownership->laborDayWeek($date->year)) {
echo " | Labor Day Week -> " . $date->copy()->firstOfMonth(Carbon::MONDAY)->format('m/d l');
}
echo "\n";
}
示例10: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$dt = Carbon::createFromDate(2016, 1, 1);
$rooms = Room::all();
foreach ($rooms as $room) {
$timeslots = $room->timeslots()->where('begin', '<=', $dt)->where('end', '>=', $dt)->where('day_id', '=', Carbon::now()->dayOfWeek)->get();
$this->controlLED($room, $timeslots);
if (sizeof($timeslots) > 0 && $this->compareTemperatures($room)) {
$this->startRelay($room);
continue;
} else {
if ($room->heatingsince != null) {
$heating = Carbon::createFromFormat('Y-m-d H:i:s', $room->heatingsince);
$heating->addMinutes($room->activeduration);
if ($heating > Carbon::now() && $this->compareTemperatures($room)) {
$this->startRelay($room);
continue;
} else {
$room->heatingsince = null;
$room->save();
}
}
}
$this->stopRelay($room);
}
}
示例11: complete_profile_post
function complete_profile_post()
{
// ------------------------------------------------------------------------------------------------------------
// SHOW DISPLAY
// ------------------------------------------------------------------------------------------------------------
$user = Auth::user();
$user->email = Input::get('email');
$user->gender = Input::get('gender');
try {
$user->dob = \Carbon\Carbon::createFromDate(Input::get('year'), Input::get('month'), Input::get('day'));
} catch (\Exception $e) {
return redirect()->back()->withInput()->withErrors('Tanggal lahir anda dalam format yang salah');
}
$rules['email'] = ['required', 'email'];
$rules['gender'] = ['required', 'in:pria,wanita'];
$rules['dob'] = ['required', 'date', 'before:-5 year'];
$validator = Validator::make(['email' => $user->email, 'gender' => $user->gender, 'dob' => $user->dob->format('Y-m-d')], $rules, ['required' => ':attribute wajib diisi', 'in' => ':attribute harus salah satu dari :values', 'dob.date' => 'tanggal lahir bukan merupakan format tanggal yang benar ', 'before' => 'Anda wajib berusia minimal 5 tahun untuk menjadi member situs kami']);
if ($validator->fails()) {
return redirect()->back()->withInput()->withErrors($validator);
} elseif (!$user->save()) {
$errors = $user->getErrors();
return redirect()->back()->withInput()->withErrors($user->getErrors());
} else {
if (Session::has('redirect')) {
$redirect = Session::get('redirect', route('web.home'));
Session::remove('redirect');
return redirect()->to($redirect);
} else {
return redirect()->route('web.home');
}
}
}
示例12: testSetDefaultEndDate
public function testSetDefaultEndDate()
{
$knownDate = Carbon::createFromDate(2001, 5, 21);
// create testing date
Carbon::setTestNow($knownDate);
$this->salary->setEndDate();
$this->assertEquals('2001-12-31', $this->tester->getPrivateProperty($this->salary, 'endDate')->toDateString());
}
示例13: testSetCarbon
public function testSetCarbon()
{
$carbon = \Carbon\Carbon::createFromDate(2015, 1, 1);
$co2 = new \HieuLe\MongoDateTime\CO2(\Carbon\Carbon::now());
$this->assertNotSame($carbon, $co2->getCarbon());
$co2->setCarbon($carbon);
$this->assertSame($carbon, $co2->getCarbon());
}
示例14: getAgeAttribute
public function getAgeAttribute()
{
if ($this->birthdate > '1901-01-01') {
return Carbon::now()->diffInYears(Carbon::createFromDate(date("Y", strtotime($this->birthdate)), date("n", strtotime($this->birthdate)), date("j", strtotime($this->birthdate))));
} else {
return false;
}
}
示例15: handle
/**
* Handle the event.
*
* @param ServiceWasUpdated $event
* @return void
*/
public function handle(ServiceWasUpdated $event)
{
foreach ($event->service->occurrences()->get() as $occurence) {
$date = \Carbon\Carbon::createFromDate($occurence->occurs_at->year, $event->service->month, $event->service->day);
$occurence->occurs_at = $date->timestamp;
$occurence->save();
}
}